Skip to content

Commit

Permalink
Fix integer overflow #2179
Browse files Browse the repository at this point in the history
  • Loading branch information
piponazo committed Apr 6, 2022
1 parent 3409ddd commit c8719cc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/jpgimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,18 @@ namespace Exiv2 {
// Write existing stuff after record,
// skip the current and all remaining IPTC blocks
long pos = sizeFront;
while (0 == Photoshop::locateIptcIrb(pPsData + pos, sizePsData - pos,
long nextSizeData = Safe::add<long>(sizePsData, -pos);
enforce(nextSizeData >= 0, ErrorCode::kerCorruptedMetadata);
while (0 == Photoshop::locateIptcIrb(pPsData + pos, nextSizeData,
&record, &sizeHdr, &sizeIptc)) {
const long newPos = static_cast<long>(record - pPsData);
// Copy data up to the IPTC IRB
if (newPos > pos) {
append(psBlob, pPsData + pos, newPos - pos);
}
// Skip the IPTC IRB
nextSizeData = Safe::add<long>(sizePsData, -pos);
enforce(nextSizeData >= 0, ErrorCode::kerCorruptedMetadata);
pos = newPos + sizeHdr + sizeIptc + (sizeIptc & 1);
}
if (pos < sizePsData) {
Expand Down

0 comments on commit c8719cc

Please sign in to comment.