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

Fix UBSAN failure caused by left-shift of negative number #1921

Merged
merged 4 commits into from
Oct 4, 2021

Conversation

kevinbackhouse
Copy link
Collaborator

Fixes: #1920

Credit to OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=39060

Add a cast to uint64_t to fix a UBSAN failure.

@kevinbackhouse kevinbackhouse added this to the v1.00 milestone Sep 22, 2021
@kevinbackhouse kevinbackhouse added bug OSS-Fuzz Bug reported by https://google.github.io/oss-fuzz/ labels Sep 22, 2021
@codecov
Copy link

codecov bot commented Sep 22, 2021

Codecov Report

Merging #1921 (83b9944) into main (7d2eb4a) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1921      +/-   ##
==========================================
- Coverage   61.13%   61.12%   -0.01%     
==========================================
  Files          96       96              
  Lines       19051    19068      +17     
  Branches     9729     9745      +16     
==========================================
+ Hits        11647    11656       +9     
- Misses       5090     5093       +3     
- Partials     2314     2319       +5     
Impacted Files Coverage Δ
src/pentaxmn_int.cpp 72.92% <100.00%> (ø)
src/makernote_int.cpp 67.62% <0.00%> (-0.72%) ⬇️
src/sonymn_int.cpp 52.88% <0.00%> (+1.12%) ⬆️

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 7d2eb4a...83b9944. Read the comment docs.

@kevinbackhouse kevinbackhouse marked this pull request as draft September 22, 2021 23:07
@kevinbackhouse kevinbackhouse marked this pull request as ready for review September 23, 2021 07:17
@kevinbackhouse
Copy link
Collaborator Author

In the third commit, I added a CodeQL query which warns about other signed shifts in the codebase. It has generated quite a few warnings, which I plan to fix in a separate PR, so that the warnings show up as "closed" on the Security tab.

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.

What about all the other warnings now?

@@ -1036,7 +1036,7 @@ namespace Exiv2 {
std::ostream& PentaxMakerNote::printDate(std::ostream& os, const Value& value, const ExifData*)
{
/* I choose same format as is used inside EXIF itself */
os << ((value.toLong(0) << 8) + value.toLong(1));
os << ((static_cast<uint64_t>(value.toLong(0)) << 8) + value.toLong(1));
Copy link
Collaborator

Choose a reason for hiding this comment

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

uint32_t doesn't cut it here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually uint16_t is probably sufficient for the intended purpose here. I think this is probably a similar scenario to #1706. The value is supposed to be a byte, but there's no validation on that, so a malicious file can contain a long instead. For the valid cases, we only need to extract the byte.

I'll change it.

@kevinbackhouse
Copy link
Collaborator Author

I can put the CodeQL query in a separate PR if you prefer. It has generated a lot of spam in the diff.

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

@kevinbackhouse kevinbackhouse merged commit be5a01f into Exiv2:main Oct 4, 2021
@kevinbackhouse kevinbackhouse deleted the FixIssue1920 branch October 4, 2021 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug OSS-Fuzz Bug reported by https://google.github.io/oss-fuzz/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UBSAN failure due to left-shift of negative number in Exiv2::Internal::PentaxMakerNote::printDate
2 participants