Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with "short" huf table and checking boundary conditions #1223

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/lib/OpenEXRCore/internal_huf.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,11 +764,16 @@ hufEncode (
c = (c << 8) | (uint64_t) (*in++); \
lc += 8

#define getCode(po, rlc, c, lc, in, out, ob, oe) \
#define getCode(po, rlc, c, lc, in, ie, out, ob, oe) \
do \
{ \
if (po == rlc) \
{ \
if (lc < 8) { getChar (c, lc, in); } \
if (lc < 8) \
{ \
if (in >= ie) return EXR_ERR_OUT_OF_MEMORY; \
getChar (c, lc, in); \
} \
\
lc -= 8; \
\
Expand All @@ -792,7 +797,7 @@ hufEncode (
{ \
return EXR_ERR_CORRUPT_CHUNK; \
} \
}
} while (0)

//
// Decode (uncompress) ni bits based on encoding & decoding tables:
Expand Down Expand Up @@ -840,7 +845,7 @@ hufDecode (
if (pl->len > lc) return EXR_ERR_CORRUPT_CHUNK;

lc -= pl->len;
getCode (pl->lit, rlc, c, lc, in, out, outb, oe)
getCode (pl->lit, rlc, c, lc, in, ie, out, outb, oe);
}
else
{
Expand Down Expand Up @@ -872,7 +877,8 @@ hufDecode (

lc -= l;
getCode (
decbuf[j], rlc, c, lc, in, out, outb, oe) break;
decbuf[j], rlc, c, lc, in, ie, out, outb, oe);
break;
}
}
}
Expand All @@ -899,7 +905,7 @@ hufDecode (
{
if (pl->len > lc) return EXR_ERR_CORRUPT_CHUNK;
lc -= pl->len;
getCode (pl->lit, rlc, c, lc, in, out, outb, oe)
getCode (pl->lit, rlc, c, lc, in, ie, out, outb, oe);
}
else
return EXR_ERR_CORRUPT_CHUNK;
Expand Down Expand Up @@ -1092,7 +1098,8 @@ internal_huf_decompress (
if (nBits > 8 * nLeft) return EXR_ERR_CORRUPT_CHUNK;

rv = hufBuildDecTable (freq, im, iM, hdec);
hufDecode (freq, hdec, ptr, nBits, iM, nRaw, raw);
if (rv == EXR_ERR_SUCCESS)
rv = hufDecode (freq, hdec, ptr, nBits, iM, nRaw, raw);

hufFreeDecTable (hdec);
}
Expand Down