Skip to content

Commit

Permalink
fix a fuzzing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phlptp committed Oct 24, 2023
1 parent 0387ff2 commit 40cf626
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions test/files/fuzz_issues/rtrip_fail36
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rc-�+A+8_A+8US6�2+B .3 %sq.23s
4 changes: 2 additions & 2 deletions test/fuzz_issue_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ TEST_P(rtripProblems, rtripFiles)
}
}

INSTANTIATE_TEST_SUITE_P(rtripFiles, rtripProblems, ::testing::Range(1, 36));
INSTANTIATE_TEST_SUITE_P(rtripFiles, rtripProblems, ::testing::Range(1, 37));

TEST(fuzzFailures, rtripSingleProblems)
{
auto cdata = loadFailureFile("rtrip_fail", 35);
auto cdata = loadFailureFile("rtrip_fail", 36);
auto u1 = unit_from_string(cdata);
if (!is_error(u1)) {
auto str = to_string(u1);
Expand Down
8 changes: 8 additions & 0 deletions units/units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5302,6 +5302,14 @@ static precise_unit
unit_string[sep + 1] == '+') {
return precise::invalid;
}
if (unit_string[sep - 1] == 'e' || unit_string[sep - 1] == 'E')
{
//this is scientific notation not addition
if (isDigitCharacter(unit_string[sep + 1]) && (sep > 1 && isDigitCharacter(unit_string[sep - 2])))
{
return precise::invalid;
}
}
precise_unit a_unit;
precise_unit b_unit;
if (sep + 1 > unit_string.size() / 2) {
Expand Down

0 comments on commit 40cf626

Please sign in to comment.