Skip to content

Commit

Permalink
Add more bounds checks in Jp2Image::encodeJp2Header
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbackhouse authored and piponazo committed Apr 22, 2021
1 parent e118d14 commit f6ee715
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/jp2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,13 +648,16 @@ static void boxes_check(size_t b,size_t m)
DataBuf output(boxBuf.size_ + iccProfile_.size_ + 100); // allocate sufficient space
long outlen = sizeof(Jp2BoxHeader) ; // now many bytes have we written to output?
long inlen = sizeof(Jp2BoxHeader) ; // how many bytes have we read from boxBuf?
enforce(sizeof(Jp2BoxHeader) <= static_cast<size_t>(output.size_), Exiv2::kerCorruptedMetadata);
Jp2BoxHeader* pBox = (Jp2BoxHeader*) boxBuf.pData_;
uint32_t length = getLong((byte*)&pBox->length, bigEndian);
enforce(length <= static_cast<size_t>(output.size_), Exiv2::kerCorruptedMetadata);
uint32_t count = sizeof (Jp2BoxHeader);
char* p = (char*) boxBuf.pData_;
bool bWroteColor = false ;

while ( count < length || !bWroteColor ) {
enforce(sizeof(Jp2BoxHeader) <= length - count, Exiv2::kerCorruptedMetadata);
Jp2BoxHeader* pSubBox = (Jp2BoxHeader*) (p+count) ;

// copy data. pointer could be into a memory mapped file which we will decode!
Expand Down

0 comments on commit f6ee715

Please sign in to comment.