Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix overflow bug on bogus code lengths #15

Merged
merged 2 commits into from
Mar 4, 2017
Merged

Fix overflow bug on bogus code lengths #15

merged 2 commits into from
Mar 4, 2017

Conversation

oyvindln
Copy link
Contributor

@oyvindln oyvindln commented Mar 4, 2017

Fixes #14

When the set of code lengths for the huffman codes encoding the main huffman tables contained a set of lengths that could not create a set of valid codes, the overflow discovered in #14 happened.

This PR checks for the overflow, and returns an error instead of overflowing.

Also added a test to check for the issue.

I don't know if the error message is descriptive enough, or if it ought to be changed.

@oyvindln
Copy link
Contributor Author

oyvindln commented Mar 4, 2017

Okay, seems overflowing_add was added in 1.7. I suppose the easiest way to fix this would be to check for code == 255 instead (The suggestion by the compiler on 1.0 doesn't seem to work with current rust). Any specific reason you need it to work with a version of rust this old?

@eddyb
Copy link
Member

eddyb commented Mar 4, 2017

@oyvindln Can't you use checked_add?

@oyvindln
Copy link
Contributor Author

oyvindln commented Mar 4, 2017

Yeah that's probably cleaner anyhow.

@oyvindln
Copy link
Contributor Author

oyvindln commented Mar 4, 2017

Okay, travis suggests it's working on 1.0 now.

@eddyb eddyb merged commit fa0bed1 into image-rs:master Mar 4, 2017
@eddyb
Copy link
Member

eddyb commented Mar 4, 2017

Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants