Skip to content

Commit

Permalink
Fix bug in calculating header size for jpeg2000.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanBloomberg committed Jun 5, 2021
1 parent 2978f81 commit 65f9d41
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
15 changes: 8 additions & 7 deletions src/boxbasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1563,16 +1563,16 @@ BOXA *boxa;
* with copies of %boxa. Any existing boxa are destroyed.
* After this operation, the number of boxa is equal to
* the number of allocated ptrs.
* (2) Note that we use boxaaReplaceBox() instead of boxaInsertBox().
* They both have the same effect when inserting into a NULL ptr
* in the boxa ptr array
* (2) Note that we use boxaaReplaceBoxa() which replaces a boxa,
* instead of boxaaInsertBoxa(), which is O(n) and shifts all
* the boxa pointers from the insertion point to the end.
* (3) Example usage. This function is useful to prepare for a
* random insertion (or replacement) of boxa into a boxaa.
* To randomly insert boxa into a boxaa, up to some index "max":
* Boxaa *baa = boxaaCreate(max);
* // initialize the boxa
* Boxa *boxa = boxaCreate(...);
* ... [optionally fix with boxes]
* ... [optionally fill with boxes]
* boxaaInitFull(baa, boxa);
* A typical use is to initialize the array with empty boxa,
* and to replace only a subset that must be aligned with
Expand Down Expand Up @@ -1695,9 +1695,10 @@ l_int32 n;
* <pre>
* Notes:
* (1) This shifts boxa[i] --> boxa[i + 1] for all i >= index,
* and then inserts boxa as boxa[index].
* (2) To insert at the beginning of the array, set index = 0.
* (3) To append to the array, it's easier to use boxaaAddBoxa().
* and then inserts boxa as boxa[index]. It is typically used
* when %baa is full of boxa.
* (2) To insert at the beginning of the array, set %index = 0.
* (3) To append to the array, it is equivalent to boxaaAddBoxa().
* (4) This should not be used repeatedly to insert into large arrays,
* because the function is O(n).
* </pre>
Expand Down
6 changes: 4 additions & 2 deletions src/jp2kheader.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ l_uint8 ihdr[4] = {0x69, 0x68, 0x64, 0x72}; /* 'ihdr' */
}
if (pcodec) *pcodec = codec;

if (4 * (12 + 3) >= size)
return ERROR_INT("header size is too small", procName, 1);
if (codec == L_JP2_CODEC) {
if (size < 4 * (windex + 3))
return ERROR_INT("header size is too small", procName, 1);
val = *((l_uint32 *)data + windex);
h = convertOnLittleEnd32(val);
val = *((l_uint32 *)data + windex + 1);
Expand All @@ -223,6 +223,8 @@ l_uint8 ihdr[4] = {0x69, 0x68, 0x64, 0x72}; /* 'ihdr' */
spp = convertOnLittleEnd16(val);
bps = *(data + 4 * (windex + 2) + 2) + 1;
} else { /* codec == L_J2K_CODEC */
if (size < 4 * (windex + 9))
return ERROR_INT("header size is too small", procName, 1);
val = *((l_uint32 *)data + windex);
w = convertOnLittleEnd32(val);
val = *((l_uint32 *)data + windex + 1);
Expand Down
2 changes: 1 addition & 1 deletion src/jp2kio.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ PIX *pix = NULL;
return NULL;
}

if (bps > 8) {
if (bps != 8) {
L_ERROR("found %d bps; can only handle 8 bps\n", procName, bps);
return NULL;
}
Expand Down

0 comments on commit 65f9d41

Please sign in to comment.