Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upUnbounded memory consumption on malformed inputs #80
Comments
added a commit
to Shnatsel/image-png
that referenced
this issue
Jun 27, 2018
Shnatsel
changed the title
Integer overflow in buffer_size()
Huge memory consumption on malformed inputs
Jun 27, 2018
This comment has been minimized.
This comment has been minimized.
|
It is also possible that the overflow is not to blame, and is merely a side effect of incorrect handling of malformed files. |
Shnatsel
changed the title
Huge memory consumption on malformed inputs
Unbounded memory consumption on malformed inputs
Jun 27, 2018
added a commit
to Shnatsel/image-png
that referenced
this issue
Jun 27, 2018
This was referenced Jun 27, 2018
This comment has been minimized.
This comment has been minimized.
newpavlov
commented
Aug 29, 2018
|
I think good solution will be to add |
pushed a commit
to zealousidealroll/image-png
that referenced
this issue
Sep 1, 2018
zealousidealroll
referenced this issue
Sep 1, 2018
Merged
Limit decoded images to 2^26 pixels by default #82
added a commit
to zealousidealroll/image-png
that referenced
this issue
Sep 6, 2018
bvssvni
closed this
in
#82
Oct 2, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shnatsel commentedJun 27, 2018
•
edited
There is an integer overflow in
image-png/src/decoder/mod.rs
Line 51 in 9938365
Aside of posing dangers for unsafe code (which shouldn't rely on this value anyway), this overflow causes enormous amounts of memory to be actually allocated when fed to
pngcrate via the fuzzing harness. Not just virtual memory - actual physical memory.The worst part is, fixing this correctly requires changing the external API: the function should use checked_mul() which returns
Option<usize>, and actually return either an Option or Result to the outside.Testcase: integer_overflow_in_multiplication found via afl-rs. Steps to reproduce the crash can be found in #79 except you need to build in debug mode, without the
--releaseflag.I would appreciate advice on how to proceed with fixing this issue. Is adding "deprecated" marker to this function in 0.12 series and releasing 0.13 with a breaking fix appropriate? Do we need the semver trick here?
Update: libpng itself also had similar issues; see https://libpng.sourceforge.io/decompression_bombs.html for more info. Among other things, they have introduced limits on the possible size of an image by default. In Rust we can easily allow the API user to override these limits via the builder pattern.