Verify multiple APNG lengths to prevent bad input from crashing.

This commit is contained in:
Cody Henthorne
2026-06-09 16:40:28 -04:00
parent 029b91066f
commit e468156c4c
5 changed files with 166 additions and 22 deletions
@@ -26,6 +26,11 @@ interface InputStreamFactory {
fun create(): InputStream
fun createRecyclable(byteArrayPool: ArrayPool): InputStream = RecyclableBufferedInputStream(create(), byteArrayPool)
/**
* An upper bound on the number of bytes [create] will yield, if cheaply knowable, else null.
*/
fun length(): Long? = null
}
/**
@@ -46,4 +51,6 @@ class FileInputStreamFactory(
throw e
}
}
override fun length(): Long? = file.length().takeIf { it > 0 }
}