Skip to content

Commit

Permalink
Merge two enforces into one.
Browse files Browse the repository at this point in the history
(cherry picked from commit 43f154f)
  • Loading branch information
kevinbackhouse authored and piponazo committed May 15, 2019
1 parent 1ed1e03 commit 8cdb330
Showing 1 changed file with 5 additions and 47 deletions.
52 changes: 5 additions & 47 deletions src/pngchunk_int.cpp
Expand Up @@ -581,23 +581,6 @@ namespace Exiv2
const char* sp = (char*)text.pData_ + 1; // current byte (space pointer)
const char* eot = (char*)text.pData_ + text.size_; // end of text

<<<<<<< HEAD
// Look for newline
while (*sp != '\n' && sp < eot) {
sp++;
if (sp == eot) {
return DataBuf();
}
}
sp++; // step over '\n'

// Look for length
while ((*sp == '\0' || *sp == ' ' || *sp == '\n') && sp < eot) {
sp++;
if (sp == eot) {
return DataBuf();
}
=======
if (sp >= eot) {
return DataBuf();
}
Expand All @@ -623,21 +606,8 @@ namespace Exiv2
if (sp == eot )
{
return DataBuf();
>>>>>>> d3e69f6d2... Add bounds check on allocation size.
}

<<<<<<< HEAD
const char* startOfLength = sp;
while (('0' <= *sp && *sp <= '9') && sp < eot) {
sp++;
if (sp == eot) {
return DataBuf();
}
}
sp++; // step over '\n'

long length = (long)atol(startOfLength);
=======
const char* startOfLength = sp;
while ('0' <= *sp && *sp <= '9')
{
Expand All @@ -653,9 +623,7 @@ namespace Exiv2
}

long length = (long) atol(startOfLength);
enforce(length >= 0, Exiv2::kerCorruptedMetadata);
enforce(length <= (eot - sp)/2, Exiv2::kerCorruptedMetadata);
>>>>>>> d3e69f6d2... Add bounds check on allocation size.
enforce(0 <= length && length <= (eot - sp)/2, Exiv2::kerCorruptedMetadata);

// Allocate space
if (length == 0) {
Expand All @@ -676,37 +644,27 @@ namespace Exiv2
unsigned char* dp = (unsigned char*)info.pData_; // decode pointer
unsigned int nibbles = length * 2;

<<<<<<< HEAD
for (long i = 0; i < (long)nibbles; i++) {
while (*sp < '0' || (*sp > '9' && *sp < 'a') || *sp > 'f') {
if (*sp == '\0') {
=======
for (long i = 0; i < (long) nibbles; i++)
{
enforce(sp < eot, Exiv2::kerCorruptedMetadata);
while (*sp < '0' || (*sp > '9' && *sp < 'a') || *sp > 'f')
{
if (*sp == '\0')
{
>>>>>>> d3e69f6d2... Add bounds check on allocation size.
#ifdef DEBUG
std::cerr << "Exiv2::PngChunk::readRawProfile: Unable To Copy Raw Profile: ran out of data\n";
#endif
return DataBuf();
}

sp++;
enforce(sp < eot, Exiv2::kerCorruptedMetadata);
}

<<<<<<< HEAD
if (i % 2 == 0)
*dp = (unsigned char)(16 * unhex[(int)*sp++]);
if (i%2 == 0)
*dp = (unsigned char) (16*unhex[(int) *sp++]);
else
(*dp++) += unhex[(int)*sp++];
=======
sp++;
enforce(sp < eot, Exiv2::kerCorruptedMetadata);
>>>>>>> d3e69f6d2... Add bounds check on allocation size.
(*dp++) += unhex[(int) *sp++];
}

return info;
Expand Down

0 comments on commit 8cdb330

Please sign in to comment.