Skip to content

Commit 036af47

Browse files
authored
Merge pull request #2194 from Exiv2/027_fix2179
[027] Fix integer overflow #2179
2 parents 3409ddd + e54f5c9 commit 036af47

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/jpgimage.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,18 @@ namespace Exiv2 {
288288
// Write existing stuff after record,
289289
// skip the current and all remaining IPTC blocks
290290
long pos = sizeFront;
291-
while (0 == Photoshop::locateIptcIrb(pPsData + pos, sizePsData - pos,
291+
long nextSizeData = Safe::add<long>(sizePsData, -pos);
292+
enforce(nextSizeData >= 0, kerCorruptedMetadata);
293+
while (0 == Photoshop::locateIptcIrb(pPsData + pos, nextSizeData,
292294
&record, &sizeHdr, &sizeIptc)) {
293295
const long newPos = static_cast<long>(record - pPsData);
294296
// Copy data up to the IPTC IRB
295297
if (newPos > pos) {
296298
append(psBlob, pPsData + pos, newPos - pos);
297299
}
298300
// Skip the IPTC IRB
301+
nextSizeData = Safe::add<long>(sizePsData, -pos);
302+
enforce(nextSizeData >= 0, kerCorruptedMetadata);
299303
pos = newPos + sizeHdr + sizeIptc + (sizeIptc & 1);
300304
}
301305
if (pos < sizePsData) {

0 commit comments

Comments
 (0)