Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vince-styling opened this issue Apr 21, 2024 · 3 comments

Comments

@vince-styling
Copy link

vince-styling commented Apr 21, 2024

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.

@redwarp
Copy link
Owner

redwarp commented Apr 22, 2024

Seems about right! I believe the gif to be corrupted: lzw minimum code size can't be > 12, according to lzw specs.
So, if for some reason, it is, then a failure would be expected.

@redwarp redwarp closed this as completed Apr 23, 2024
@vince-styling
Copy link
Author

1718881878793
hi,I found an example eventually for this issue,take a look

@redwarp
Copy link
Owner

redwarp commented Jul 1, 2024

Thanks! I'll take a look.

@redwarp redwarp reopened this Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants