-
Notifications
You must be signed in to change notification settings - Fork 624
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
Added overflow handling to multiplication of width and components #1619
Conversation
There are multiple ways to solve this, but what I would suggest doing is something like let row_size = match width.checked_mul(components) {
Some(n) => n,
None => return Err(<some error>),
}; Also, it's not entirely clear that using I'd keep it as a For the error... there doesn't look to be a good error to return already. So you'll want to make a new one. To do that, you'll need to add a new enum variant to the /// The row was too wide and overflowed in multiplication
RowTooWide {
width: u32,
components: u32,
}, And then you'll need to add a human readable error for this. I'd say what the width and the components were, like DecoderError::RowTooWide { width, components } =>
f.write_fmt(format_args!("Row too wide: have width={}, components={}", width, components)), And finally, I'd add a test. You can add the test at the bottom of Sorry about the wall of text! If anything's unclear, feel free to ask. Also pinging @fintelia since i'm not sure if my suggestion to keep it as a |
We use |
@shikharvashistha thanks for this PR! It isn't quite ready to merge yet, but we can work through some changes to get everything working. First off, could you make sure you able to run Next, I should perhaps provide more detailed directions. When I suggested changing the argument type, I mean changing line 201 so that from_bytes's second argument is image/src/codecs/pnm/decoder.rs Line 201 in 0f1c38a
Once you make that change, you'll see a couple compiler errors generated. These indicate places where other code has to be updated to get the types to match. Most of these should be straightforward to fix, but please ask questions if you get stuck. |
Apologies for the delay I got busy in some university commitment, cargo check && cargo test seems to be passing/working for me now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seem like there is more panic after the changes, please review the code and see if the comments can help fix that.
Apologies, it's difficult for me to complete it at this time due to other time bound commitments, other's who are interested can take up the challenge. |
Thanks for the notification, if you keep the branch and repository up then we (meaning anyone with write-access to this repository) can push further work into it. No problems at all, thanks for everything done already :) |
8e93411
to
2847d9d
Compare
Greetings of the day @fintelia,
I've fixed the issue as suggested, kindly review the pull and suggest changes if any.
Thanks & Regards
@shikharvashistha
Fixes : #1616