Skip to content

ArrayIndexOutOfBoundsException: length=4096; index=4096 at LzwDecoder.decode() #29

@vince-styling

Description

@vince-styling

Hi, the decode step would cause ArrayIndexOutOfBoundsException sometime

private const val MAX_STACK_SIZE = 4096
private val prefix = ShortArray(MAX_STACK_SIZE)

fun decode(imageData: ByteArray, destination: ByteArray, pixelCount: Int) {
val lzwMinimumCodeSize = imageData[dataIndex]
val clear: Int = 1.shl(lzwMinimumCodeSize.toInt())

for (code in 0 until clear) {
    prefix[code] = 0
    suffix[code] = code.toByte()
}

once lzwMinimumCodeSize's value greater than 12, I can't make sure that gif file is corrupted or not due to it happened from my user's devices, but it is infrequent, the last report was two months ago, about 20 times totally, probably the files was broken.

just to ask if you have any idea.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions