-
Notifications
You must be signed in to change notification settings - Fork 89
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
Panic: attempt to subtract with overflow #132
Comments
FYI |
Ah, interesting. What's the difference between |
I believe the latter will, yes. I'm not 100% sure, test it if you need to rely on that behavior. |
The panic in happening on this line. I don't know the code well enough to say what is going on there or what the right way to handle underflow would be, but it kind of looks like it is trying to compute |
- Fixes image-rs#132 - improve readability - improve performance Criterion report on my computer: Benchmarking decode a 512x512 progressive JPEG: Collecting 100 samples in estimated 27.108 s (5050 i decode a 512x512 progressive JPEG time: [5.3440 ms 5.3549 ms 5.3669 ms] change: [-24.307% -23.085% -21.920%] (p = 0.00 < 0.05) Performance has improved. Found 3 outliers among 100 measurements (3.00%) 2 (2.00%) high mild 1 (1.00%) high severe
- Fixes image-rs#132 - improve readability - improve performance Criterion report on my computer: Benchmarking decode a 512x512 progressive JPEG: Collecting 100 samples in estimated 27.108 s (5050 i decode a 512x512 progressive JPEG time: [5.3440 ms 5.3549 ms 5.3669 ms] change: [-24.307% -23.085% -21.920%] (p = 0.00 < 0.05) Performance has improved. Found 3 outliers among 100 measurements (3.00%) 2 (2.00%) high mild 1 (1.00%) high severe
This is an incorrect reading, although it would make things a lot easier if it were the case. [edit: stuff removed, see next post for a more correct analysis] To look at the spec:
All that said, I think the current code may be incorrect: The current code is as follows:
I believe the check on This is a RAW (read-as-written) rather than likely RAI (read-as-intended) interpretation though. I think the RAI is that subsequent approximation passes add on individual bits (the current code); this appears to be the guidance in the spec for encoders to follow. A RAW interpretation is that a poor encoder could encode multiple passes on the same bits, to incrementally increase them or decrease them. I guess this really depends upon how we'd like to handle weird cases like this. Simple encoders would likely be fine with the existing code, but unless I'm reading the spec wrong, I can see cases where this wouldn't be applicable. As for OP's issue, even though it's clearly a pathological case, I think the expected operation here would be a |
Actually, further reading clarified things a bit, apologies. It looks like there are no cases where positive coefficients would be given a negative correction value, or vice-versa. The first pass (zero-history) should always look like: Non-zero history should always look like: I guess we'll consider each case then for the non-zero history: In the negative coefficient case, a simple |
Decoding the following input file crashes in debug mode (but not in release mode, because overflows silently wrap in release mode).
id:000000,sig:06,src:000000,op:flip2,pos:1027.tar.gz
Found using afl (see #131).
Potentially related to #63.
The text was updated successfully, but these errors were encountered: