Skip to content

Commit

Permalink
parser: Fix types for out-of-bound checks
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Mar 2, 2021
1 parent 7cbbf3a commit 9e826d0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/fizzy/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ parser_result<std::string> parse_string(const uint8_t* pos, const uint8_t* end)
uint32_t size;
std::tie(size, pos) = leb128u_decode<uint32_t>(pos, end);

if ((end - pos) < size)
assert(pos <= end);
if (static_cast<size_t>(end - pos) < size)
throw parser_error{"unexpected EOF"};

if (!utf8_validate(pos, pos + size))
Expand Down Expand Up @@ -442,7 +443,8 @@ inline parser_result<Data> parse(const uint8_t* pos, const uint8_t* end)
uint32_t size;
std::tie(size, pos) = leb128u_decode<uint32_t>(pos, end);

if ((end - pos) < size)
assert(pos <= end);
if (static_cast<size_t>(end - pos) < size)
throw parser_error{"unexpected EOF"};

auto init = bytes(pos, pos + size);
Expand Down Expand Up @@ -474,7 +476,8 @@ std::unique_ptr<const Module> parse(bytes_view input)
uint32_t size;
std::tie(size, it) = leb128u_decode<uint32_t>(it, input.end());

if ((input.end() - it) < size)
assert(it <= input.end());
if (static_cast<size_t>(input.end() - it) < size)
throw parser_error{"unexpected EOF"};

const auto expected_section_end = it + size;
Expand Down

0 comments on commit 9e826d0

Please sign in to comment.