|
|
240d3a |
From 06aa7ab69d0c4f3d14644bd84fc9d1346154430d Mon Sep 17 00:00:00 2001
|
|
|
240d3a |
From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= <dan.cermak@cgc-instruments.com>
|
|
|
240d3a |
Date: Mon, 22 Jan 2018 23:56:08 +0100
|
|
|
240d3a |
Subject: Fix out of bounds read in src/pngchunk_int.cpp by @brianmay
|
|
|
240d3a |
|
|
|
240d3a |
- consider that key is advanced by 8 bytes if stripHeader is true
|
|
|
240d3a |
=> length is reduced by same amount
|
|
|
240d3a |
Fixed by adding offset to the check in the loop
|
|
|
240d3a |
- Rewrote loop so that keysize is checked before the next
|
|
|
240d3a |
iteration (preventing an out of bounds read)
|
|
|
240d3a |
|
|
|
240d3a |
diff --git a/src/pngchunk.cpp b/src/pngchunk.cpp
|
|
|
240d3a |
index da4ccd01..b54bcdac 100644
|
|
|
240d3a |
--- a/src/pngchunk.cpp
|
|
|
240d3a |
+++ b/src/pngchunk.cpp
|
|
|
240d3a |
@@ -107,15 +107,17 @@ namespace Exiv2 {
|
|
|
240d3a |
{
|
|
|
240d3a |
// From a tEXt, zTXt, or iTXt chunk,
|
|
|
240d3a |
// we get the key, it's a null terminated string at the chunk start
|
|
|
240d3a |
- if (data.size_ <= (stripHeader ? 8 : 0)) throw Error(14);
|
|
|
240d3a |
- const byte *key = data.pData_ + (stripHeader ? 8 : 0);
|
|
|
240d3a |
+ const int offset = stripHeader ? 8 : 0;
|
|
|
240d3a |
+ if (data.size_ <= offset) throw Error(14);
|
|
|
240d3a |
+ const byte *key = data.pData_ + offset;
|
|
|
240d3a |
|
|
|
240d3a |
// Find null string at end of key.
|
|
|
240d3a |
int keysize=0;
|
|
|
240d3a |
- for ( ; key[keysize] != 0 ; keysize++)
|
|
|
240d3a |
+ while (key[keysize] != 0)
|
|
|
240d3a |
{
|
|
|
240d3a |
+ keysize++;
|
|
|
240d3a |
// look if keysize is valid.
|
|
|
240d3a |
- if (keysize >= data.size_)
|
|
|
240d3a |
+ if (keysize+offset >= data.size_)
|
|
|
240d3a |
throw Error(14);
|
|
|
240d3a |
}
|
|
|
240d3a |
|