prevent crash when editing mp4 with large moov box

This commit is contained in:
Thibault Deckers 2023-04-18 19:46:43 +02:00
parent 94af48a97f
commit 5f71651baa

View file

@ -238,6 +238,7 @@ object Mp4ParserHelper {
} }
fun Box.toBytes(): ByteArray { fun Box.toBytes(): ByteArray {
if (size > BOX_SIZE_DANGER_THRESHOLD) throw Exception("box (type=$type size=$size) is too large")
val stream = ByteArrayOutputStream(size.toInt()) val stream = ByteArrayOutputStream(size.toInt())
Channels.newChannel(stream).use { getBox(it) } Channels.newChannel(stream).use { getBox(it) }
return stream.toByteArray() return stream.toByteArray()