Skip to content

Commit e078172

Browse files
authored
Add sanity check for tile coordinates (#823)
Coordinates are casted from OPJ_UINT32 to OPJ_INT32 Add sanity check for negative values and upper bound becoming lower than lower bound. See also https://pdfium.googlesource.com/pdfium/+/b6befb2ed2485a3805cddea86dc7574510178ea9
1 parent acfb307 commit e078172

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

Diff for: src/lib/openjp2/tcd.c

+11
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,20 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
696696
l_tx0 = l_cp->tx0 + p * l_cp->tdx; /* can't be greater than l_image->x1 so won't overflow */
697697
l_tile->x0 = (OPJ_INT32)opj_uint_max(l_tx0, l_image->x0);
698698
l_tile->x1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_tx0, l_cp->tdx), l_image->x1);
699+
/* all those OPJ_UINT32 are casted to OPJ_INT32, let's do some sanity check */
700+
if ((l_tile->x0 < 0) || (l_tile->x1 <= l_tile->x0)) {
701+
opj_event_msg(manager, EVT_ERROR, "Tile X coordinates are not supported\n");
702+
return OPJ_FALSE;
703+
}
699704
l_ty0 = l_cp->ty0 + q * l_cp->tdy; /* can't be greater than l_image->y1 so won't overflow */
700705
l_tile->y0 = (OPJ_INT32)opj_uint_max(l_ty0, l_image->y0);
701706
l_tile->y1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_ty0, l_cp->tdy), l_image->y1);
707+
/* all those OPJ_UINT32 are casted to OPJ_INT32, let's do some sanity check */
708+
if ((l_tile->y0 < 0) || (l_tile->y1 <= l_tile->y0)) {
709+
opj_event_msg(manager, EVT_ERROR, "Tile Y coordinates are not supported\n");
710+
return OPJ_FALSE;
711+
}
712+
702713

703714
/* testcase 1888.pdf.asan.35.988 */
704715
if (l_tccp->numresolutions == 0) {

Diff for: tests/compare_dump_files.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ int main(int argc, char **argv)
118118
test_cmp_parameters inParam;
119119
FILE *fbase=NULL, *ftest=NULL;
120120
int same = 0;
121-
char lbase[256];
122-
char strbase[256];
123-
char ltest[256];
124-
char strtest[256];
121+
char lbase[512];
122+
char strbase[512];
123+
char ltest[512];
124+
char strtest[512];
125125

126126
if( parse_cmdline_cmp(argc, argv, &inParam) == 1 )
127127
{
@@ -154,9 +154,9 @@ int main(int argc, char **argv)
154154

155155
while (fgets(lbase, sizeof(lbase), fbase) && fgets(ltest,sizeof(ltest),ftest))
156156
{
157-
int nbase = sscanf(lbase, "%255[^\r\n]", strbase);
158-
int ntest = sscanf(ltest, "%255[^\r\n]", strtest);
159-
assert( nbase != 255 && ntest != 255 );
157+
int nbase = sscanf(lbase, "%511[^\r\n]", strbase);
158+
int ntest = sscanf(ltest, "%511[^\r\n]", strtest);
159+
assert( nbase != 511 && ntest != 511 );
160160
if( nbase != 1 || ntest != 1 )
161161
{
162162
fprintf(stderr, "could not parse line from files\n" );

Diff for: tests/nonregression/test_suite.ctest.in

+3
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,6 @@ opj_decompress -i @INPUT_NR_PATH@/issue726.j2k -o @TEMP_PATH@/issue726.png
566566
!opj_decompress -i @INPUT_NR_PATH@/issue775-2.j2k -o @TEMP_PATH@/issue775-2.png
567567
# issue 818
568568
opj_decompress -i @INPUT_NR_PATH@/issue818.jp2 -o @TEMP_PATH@/issue818.png
569+
# issue 823 (yes, not a typo, test image is issue822)
570+
!opj_decompress -i @INPUT_NR_PATH@/issue822.jp2 -o @TEMP_PATH@/issue822.png
571+

0 commit comments

Comments
 (0)