Skip to content

Commit d9c57a3

Browse files
author
Kai Dietrich
committed
Fix length checks in zip_file::remove_comment()
1 parent cb2221e commit d9c57a3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

zip_file.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5651,10 +5651,20 @@ class zip_file
56515651
throw std::runtime_error("didn't find end of central directory signature");
56525652
}
56535653

5654+
if (position + 2 >= buffer_.size())
5655+
{
5656+
throw std::runtime_error("central dictionary position invalid");
5657+
}
5658+
56545659
uint16_t length = static_cast<uint16_t>(buffer_[position + 1]);
56555660
length = static_cast<uint16_t>(length << 8) + static_cast<uint16_t>(buffer_[position]);
56565661
position += 2;
56575662

5663+
if (position + length > buffer_.size())
5664+
{
5665+
throw std::runtime_error("comment too long");
5666+
}
5667+
56585668
if(length != 0)
56595669
{
56605670
comment = std::string(buffer_.data() + position, buffer_.data() + position + length);

0 commit comments

Comments
 (0)