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

Invalid huffman exception when reading .png via format via heaps #8875

Closed
Simn opened this issue Oct 14, 2019 · 5 comments
Closed

Invalid huffman exception when reading .png via format via heaps #8875

Simn opened this issue Oct 14, 2019 · 5 comments

Comments

@Simn
Copy link
Member

@Simn Simn commented Oct 14, 2019

I don't have a small reproducible example yet, but something seems to be wrong in haxe.zip or format:

Code_2019-10-14_11-16-23

I'm using this via a heaps texture, but I doubt that matters. The .png I'm trying to load works fine in other programs.

@Simn

This comment has been minimized.

Copy link
Member Author

@Simn Simn commented Oct 14, 2019

The problem is in HuffTools.make:

return treeCompress(NeedBit(treeMake(bits, maxbits, 0, 1), treeMake(bits, maxbits, 1, 1)));

This assumes that there is more than 1 entry, but in my case nlengths is 1, which means that there is no right-part of the tree. The call to treeMake(bits, maxbits, 1, 1) then recurses indefinitely (well, until the maxbits check fails) because bits has no corresponding entry, which means the exit condition is never fulfilled.

I can fix this by replacing the code with this:

var left = treeMake(bits, maxbits, 0, 1);
var right = nlengths > 1 ? treeMake(bits, maxbits, 1, 1) : Found(0);
return treeCompress(NeedBit(left, right));

However, I have no idea what I'm doing and using Found(0) seems very random.

@ncannasse: Any advice?

@Aurel300

This comment has been minimized.

Copy link
Contributor

@Aurel300 Aurel300 commented Oct 14, 2019

nlengths passed to Huffman.make is 1? Meaning there is only one symbol? That might be a special case for the make function, it could just return NeedBit(Found(0), Found(0)) immediately. Then InflateImpl.applyHuffman consumes at least one bit for the symbol.

@Simn

This comment has been minimized.

Copy link
Member Author

@Simn Simn commented Oct 14, 2019

Right, I suppose we don't have to recurse at all in that case.

@Simn Simn closed this in 7209f37 Oct 14, 2019
@ncannasse

This comment has been minimized.

Copy link
Member

@ncannasse ncannasse commented Oct 15, 2019

BTW that's a very slow way to read PNGs ;)

@Simn

This comment has been minimized.

Copy link
Member Author

@Simn Simn commented Oct 15, 2019

Well, it's what heaps does. When targeting JS anyway.

RealyUniqueName added a commit that referenced this issue Nov 27, 2019
closes #8875
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.