Skip to content
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

[main] Fix integer overflow #2179 #2181

Merged
merged 6 commits into from
Apr 6, 2022
Merged

[main] Fix integer overflow #2179 #2181

merged 6 commits into from
Apr 6, 2022

Conversation

piponazo
Copy link
Collaborator

Fix #2179

I considered adding a python test to process the POC file, but I realised that the exiv2 application is not exercising the part of the code that has been modified. In #2179 @kevinbackhouse mentioned that in order to reproduce the issue, one needs to use the fuzz-read-print-write application. However that application only gets compiled in the FUZZ jobs.

Any ideas of how we could try to exercise that part of the code with a python test?

Other possibility would be to try to add a unit test which directly calls Photoshop::setIptcIrb. It might be a good opportunity for me to get more familiar with that part of the code base.

@codecov
Copy link

codecov bot commented Mar 31, 2022

Codecov Report

Merging #2181 (a505d6f) into main (6e9eca4) will increase coverage by 0.04%.
The diff coverage is 91.66%.

@@            Coverage Diff             @@
##             main    #2181      +/-   ##
==========================================
+ Coverage   63.29%   63.34%   +0.04%     
==========================================
  Files          99       99              
  Lines       19591    19595       +4     
  Branches     9556     9560       +4     
==========================================
+ Hits        12400    12412      +12     
+ Misses       5117     5112       -5     
+ Partials     2074     2071       -3     
Impacted Files Coverage Δ
src/psdimage.cpp 52.25% <50.00%> (ø)
src/jpgimage.cpp 71.98% <100.00%> (+1.36%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6e9eca4...a505d6f. Read the comment docs.

@piponazo piponazo self-assigned this Mar 31, 2022
@piponazo piponazo force-pushed the main_issue2179 branch 4 times, most recently from a8d113a to 2a2f164 Compare April 6, 2022 07:10
@piponazo piponazo marked this pull request as ready for review April 6, 2022 07:25
size_t pos = sizeFront;
while (0 == Photoshop::locateIptcIrb(pPsData + pos, sizePsData - pos, &record, &sizeHdr, &sizeIptc)) {
long nextSizeData = Safe::add<long>(static_cast<long>(sizePsData), -static_cast<long>(pos));
enforce(nextSizeData >= 0, ErrorCode::kerCorruptedMetadata);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is in lines 188-189 & 196-197. I ended up using Safe::add<long> to make sure that there is not integer overflow and I also used later enforce to make sure that the substraction is positive.


TEST(Photoshop_setIptcIrb, detectIntegerOverflow_withDataFromPOC2179) {
const std::array<byte, 141> data{
0x38, 0x42, 0x49, 0x4d, 0x20, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x38, 0x42, 0x49, 0x4d, 0x04, 0x04,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the test which is replicating the case detected by oss-fuzz. Note that the assertion is checking that an exception is thrown.

@piponazo piponazo changed the title Fix integer overflow #2179 [main] Fix integer overflow #2179 Apr 6, 2022
@piponazo piponazo requested review from neheb, hassec and kmilos April 6, 2022 13:06
kmilos
kmilos previously approved these changes Apr 6, 2022
Copy link
Collaborator

@kmilos kmilos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

It has been detected that we need to always pass the size==4 in the call
to isIrb. Probably it is better to remove that parameter and document
that it is assumed for the buffer to have a length of 4 bytes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integer overflow in Photoshop::setIptcIrb
2 participants