summaryrefslogtreecommitdiff
path: root/src/lib/openjp2/t2.c
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2017-08-16 17:20:29 +0200
committerEven Rouault <even.rouault@spatialys.com>2017-08-16 17:20:29 +0200
commitc535531f03369623b9b833ef41952c62257b507e (patch)
treec522e8a0a49accf0149e1caa6b2b443e1525fec4 /src/lib/openjp2/t2.c
parentdcac91b8c72f743bda7dbfa9032356bc8110098a (diff)
opj_t2_encode_packet(): fix potential write heap buffer overflow (#992)
Diffstat (limited to 'src/lib/openjp2/t2.c')
-rw-r--r--src/lib/openjp2/t2.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c
index 9d31acda..0fd5300c 100644
--- a/src/lib/openjp2/t2.c
+++ b/src/lib/openjp2/t2.c
@@ -629,6 +629,15 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno,
/* <SOP 0xff91> */
if (tcp->csty & J2K_CP_CSTY_SOP) {
+ if (length < 6) {
+ if (p_t2_mode == FINAL_PASS) {
+ opj_event_msg(p_manager, EVT_ERROR,
+ "opj_t2_encode_packet(): only %u bytes remaining in "
+ "output buffer. %u needed.\n",
+ length, 6);
+ }
+ return OPJ_FALSE;
+ }
c[0] = 255;
c[1] = 145;
c[2] = 0;
@@ -817,6 +826,15 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno,
/* <EPH 0xff92> */
if (tcp->csty & J2K_CP_CSTY_EPH) {
+ if (length < 2) {
+ if (p_t2_mode == FINAL_PASS) {
+ opj_event_msg(p_manager, EVT_ERROR,
+ "opj_t2_encode_packet(): only %u bytes remaining in "
+ "output buffer. %u needed.\n",
+ length, 2);
+ }
+ return OPJ_FALSE;
+ }
c[0] = 255;
c[1] = 146;
c += 2;