From f5b40f3e82da9b3968f23534a453ddcc80a9a0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20D=C3=ADaz=20M=C3=A1s?= Date: Mon, 3 Sep 2018 08:51:08 +0200 Subject: [PATCH] Fix more issues in PngChunk::readRawProfile --- src/pngchunk_int.cpp | 36 +++++++++++++----------- test/data/issue_428_poc3.png | Bin 0 -> 512 bytes test/data/issue_428_poc4.png | Bin 0 -> 188 bytes tests/bugfixes/github/test_issue_428.py | 8 ++++-- 4 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 test/data/issue_428_poc3.png create mode 100644 test/data/issue_428_poc4.png diff --git a/src/pngchunk_int.cpp b/src/pngchunk_int.cpp index 755872c9..9b3faf1a 100644 --- a/src/pngchunk_int.cpp +++ b/src/pngchunk_int.cpp @@ -606,11 +606,6 @@ namespace Exiv2 { DataBuf PngChunk::readRawProfile(const DataBuf& text,bool iTXt) { DataBuf info; - register long i; - register unsigned char *dp; - const char *sp; - unsigned int nibbles; - long length; unsigned char unhex[103]={0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,1, 2,3,4,5,6,7,8,9,0,0, @@ -627,8 +622,7 @@ namespace Exiv2 { return info; } - - sp = (char*)text.pData_+1; + const char *sp = (char*)text.pData_+1; int pointerPos = 1; // Look for newline @@ -638,20 +632,30 @@ namespace Exiv2 { pointerPos++; } + // Look for length + while ((*sp == '\0' || *sp == ' ' || *sp == '\n') && pointerPos < (text.size_ - 1)) + { + sp++; + pointerPos++; + } + if (pointerPos == (text.size_ - 1)) { return DataBuf(); } - // Look for length + long length = (long) atol(sp); - while (*sp == '\0' || *sp == ' ' || *sp == '\n') + while (*sp != ' ' && *sp != '\n' && pointerPos < (text.size_ - 1)) + { sp++; + pointerPos++; + } - length = (long) atol(sp); - - while (*sp != ' ' && *sp != '\n') - sp++; + if (pointerPos == (text.size_ - 1)) + { + return DataBuf(); + } // Allocate space @@ -674,10 +678,10 @@ namespace Exiv2 { // Copy profile, skipping white space and column 1 "=" signs - dp = (unsigned char*)info.pData_; - nibbles = length * 2; + unsigned char *dp = (unsigned char*)info.pData_; + unsigned int nibbles = length * 2; - for (i = 0; i < (long) nibbles; i++) + for (long i = 0; i < (long) nibbles; i++) { while (*sp < '0' || (*sp > '9' && *sp < 'a') || *sp > 'f') { diff --git a/test/data/issue_428_poc3.png b/test/data/issue_428_poc3.png new file mode 100644 index 0000000000000000000000000000000000000000..ae6fa0a721b00b113e0f8f39550bfa98b5a798e5 GIT binary patch literal 512 zcmeAS@N?(olHy`uVBq!ia0vp^xRy9`kFKLcEr3#t;N`U4{e!#kigAT|ht2)I5V7iKC* z4rt3WK}J!al9xanD4(Mbv}+~Yp44%Q12$LeN&oNg8XnFqo^dwC&l2JtCzGs2HVxcOx>&~j-; GRt5n77D`K@GchpCWMF6kDiCMnf~yl}