Hitomi: fix animated webp & potential oom (#9600)

* animated images can be webp

closes https://github.com/keiyoushi/extensions-source/issues/9554

* avoid internal resize overhead of HashSet

* bump

* import
This commit is contained in:
AwkwardPeak7 2025-07-11 10:20:40 +05:00 committed by Draff
parent d773d2692b
commit 296a7bf55d
Signed by: Draff
GPG Key ID: E8A89F3211677653
3 changed files with 11 additions and 5 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'Hitomi'
extClass = '.HitomiFactory'
extVersionCode = 40
extVersionCode = 41
isNsfw = true
}

View File

@ -32,6 +32,7 @@ import java.nio.ByteBuffer
import java.nio.ByteOrder
import java.security.MessageDigest
import java.text.SimpleDateFormat
import java.util.LinkedHashSet
import java.util.LinkedList
import java.util.Locale
import kotlin.math.min
@ -308,8 +309,6 @@ class Hitomi(
val inbuf = getRangedResponse(url, offset.until(offset + length))
val galleryIDs = mutableSetOf<Int>()
val buffer =
ByteBuffer
.wrap(inbuf)
@ -326,6 +325,9 @@ class Hitomi(
"inbuf.byteLength ${inbuf.size} != expected_length $expectedLength"
}
// we know total number so avoid internal resize overhead
val galleryIDs = LinkedHashSet<Int>(numberOfGalleryIDs, 1.0f)
for (i in 0.until(numberOfGalleryIDs))
galleryIDs.add(buffer.int)
@ -404,12 +406,16 @@ class Hitomi(
}
val bytes = getRangedResponse(nozomiAddress, range)
val nozomi = mutableSetOf<Int>()
val arrayBuffer = ByteBuffer
.wrap(bytes)
.order(ByteOrder.BIG_ENDIAN)
val size = arrayBuffer.remaining() / Int.SIZE_BYTES
// we know total number so avoid internal resize overhead
val nozomi = LinkedHashSet<Int>(size, 1.0f)
while (arrayBuffer.hasRemaining())
nozomi.add(arrayBuffer.int)

View File

@ -24,7 +24,7 @@ class ImageFile(
val hash: String,
private val name: String,
) {
val isGif get() = name.endsWith(".gif")
val isGif get() = name.endsWith(".gif") || name.endsWith(".webp")
}
@Serializable