Skip to content

Commit

Permalink
Check extra field data size before subtracting from remaining count
Browse files Browse the repository at this point in the history
because it is an unsigned value.
  • Loading branch information
kimci86 committed Mar 16, 2024
1 parent 83fc5de commit 24d7319
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ auto Zip::Iterator::operator++() -> Zip::Iterator&

m_entry->checkByte = (flags >> 3) & 1 ? static_cast<std::uint8_t>(lastModTime >> 8) : msb(m_entry->crc32);

for (auto remaining = extraFieldLength; remaining > 0;)
for (auto remaining = extraFieldLength; remaining;)
{
// read extra field header
const auto id = read<std::uint16_t>(*m_is);
auto size = read<std::uint16_t>(*m_is);

if (remaining < 4 + size)
throw Error{"could not read central directory header"};
remaining -= 4 + size;

switch (id)
Expand Down

0 comments on commit 24d7319

Please sign in to comment.