diff --git a/src/Zip.cpp b/src/Zip.cpp index c79dacb..bb42b13 100644 --- a/src/Zip.cpp +++ b/src/Zip.cpp @@ -155,11 +155,14 @@ auto Zip::Iterator::operator++() -> Zip::Iterator& m_entry->checkByte = (flags >> 3) & 1 ? static_cast(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(*m_is); auto size = read(*m_is); + + if (remaining < 4 + size) + throw Error{"could not read central directory header"}; remaining -= 4 + size; switch (id)