-
Notifications
You must be signed in to change notification settings - Fork 281
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
Fixed wrong brackets: size*count + pad can overflow before the cast #79
Conversation
=> Should fix Exiv2#76 (most of the work has been done by Robin Mills in 6e3855a) The problem with Exiv2#76 is the contents of the 26th IFD, with the following contents: tag: 0x8649 type: 0x1 count: 0xffff ffff offset: 0x4974 The issue is the size of count (uint32_t), as adding anything to it causes an overflow. Especially the expression: (size*count + pad+20) results in an overflow and gives 20 as a result instead of 0x100000014, thus the condition in the if in the next line is false and the program continues to run (until it crashes at io.read). To properly account for the overflow, the brackets have to be removed, as then the result is saved in the correctly sized type and not cast after being calculated in the smaller type. The brackets have also been removed from bigtiffimage.cpp, where the same issue is present.
I have cherry-picked the respective commits on top of the commit tagged with v0.26 and pushed them here. The invalid free does then no longer appear in v0.26. |
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.
-
There's similar code in bigtiffimage.cpp. bigtiffimage.cpp is in development and not used in production yet, however it's almost identical code. One day bigtiffimage.cpp will replace tiffimage.cpp (assuming the work involved doesn't kill Michal!).
-
I'm amazed by this fix. I put in the brackets in an effort to tell the compiler "Do this in 64 bit". I was worried that your version would say "cast size" and do whatever you want with the rest of the expression!
-
If you are confident that the whole expression is 64 bit, I'm happy. However please deal with bigtiffimage.cpp
|
This is really good. I've updated the test suite with the file POC2 from #49. 7fa8d31
I think we've fixed two issues with this. Unusual. It's more common to discover more issues with one fix. Occasionally we win and get two issues with one fix. Maybe it's an omen that VS11 will crash into the Atlantic this evening! |
Make it three. CVE-2017-11337 (aka #50) seems to be fixed by this PR
too.
However, our work is not yet done. We still have to cherry pick the
respective commits, apply them to the old releases and provide the
packagers with the appropriate patches.
|
Should fix #76 for the current git head.
However the credit goes to Robin Mills (@clanmills), as he mostly fixed it in 6e3855a.
The problem with #76 is the contents of the 26th TIFF IFD, with the following contents:
tag: 0x8649
type: 0x1
count: 0xffff ffff
offset: 0x4974
The issue is the size of count (uint32_t), as adding anything to it causes an overflow. Especially the expression:
(size*count + pad+20)
(from here)results in an overflow and gives 20 as a result instead of 0x100000014, thus the condition in the if in the next line is false and the program continues to run (until it crashes at io.read where the overflow does not occur).
To properly account for the overflow, the brackets have to be removed, as then the result is saved in the correctly sized type and not cast after being calculated in the smaller type.
The brackets have also been removed from bigtiffimage.cpp, where the same issue is present.
I am not 100% sure, if this fully fixes #76, as it was reported against v0.26 and I fixed in in the current git head. I'll try to cherry pick the necessary patches onto v0.26 and see if they fix it there, too.