Compare commits

..

40 Commits

Author SHA1 Message Date
Antonin Descampe
8ddbe4dc4d [wg1n6848] added CHANGES file 2014-10-23 10:45:06 +00:00
Antonin Descampe
0ac0b3d823 [newtag] created wg1n6848 tag corresponding to submitted package for 15444-5 AMD2 additional reference software for JPEG 2000 Part-1 2014-10-23 10:40:45 +00:00
Antonin Descampe
09fb8b6989 [trunk] add Aaron Boxer as contributor 2014-10-22 23:01:04 +00:00
Antonin Descampe
9e6c62199a [trunk] re-arrange contributors alphabetically and add Matthieu Darbois 2014-10-22 22:59:35 +00:00
Antonin Descampe
d47f7a249d [trunk] workaround to make MD5 work under valgrind on MacOSX (fixes issue 410) 2014-10-22 22:52:01 +00:00
Antonin Descampe
7280263988 [trunk] Added new non-regression tests from foxit issues
Update issue 415
2014-10-22 22:38:55 +00:00
Antonin Descampe
3e1fad2da4 [trunk] resets resno_decoded for each tile (fixes issue 399) 2014-10-22 13:16:35 +00:00
Antonin Descampe
d72940c56b [trunk] resets code-blocks reused for other tiles than the first one (fixes issue 418) 2014-10-22 13:16:12 +00:00
Antonin Descampe
ad4fad0965 [trunk] add a check on mandatory headers in Main Header (fixes issue 408) 2014-10-22 10:30:35 +00:00
Antonin Descampe
aff9cb39ed [trunk] fixed invalid member values from opj_read_header or opj_decode (fixes issue 411) 2014-10-21 15:22:22 +00:00
Antonin Descampe
0a3f234df7 [trunk] verify channel definitions is complete when cdef is present (fixes issue 397) 2014-10-21 12:54:08 +00:00
Antonin Descampe
efb70af001 [trunk] add a check on the number of resolution passed to cmdline (fixes issue 352) 2014-10-21 12:47:48 +00:00
Antonin Descampe
e65303b903 [trunk] added check on JP2_IHDR box (fixes issue 364) 2014-10-21 12:35:16 +00:00
Antonin Descampe
413de4fbfa [trunk] add a check on Zppm value in PPM markers (fixes issue 393) 2014-10-21 12:27:58 +00:00
Antonin Descampe
984351f86f [trunk] Add option to call dsymutil on built binaries (fixes issue 409) 2014-10-15 10:24:49 +00:00
Antonin Descampe
f8796711e8 [trunk] add a check on progression order (fixes issue 413) 2014-10-15 10:14:54 +00:00
Antonin Descampe
0b540067b1 [trunk] add a check for illegal SCod value (fixes issue 400) 2014-10-15 08:48:19 +00:00
Antonin Descampe
3df347eded [trunk] additional checks for marker size inconsistency (fixes issue 363) 2014-10-14 15:15:09 +00:00
Antonin Descampe
eb7c6d295a [trunk] fixed potential negative size params (fixes issue 390) 2014-10-06 21:05:32 +00:00
Antonin Descampe
f126eb0d41 [trunk] added box length inconsistency check
Update issue 364

issue364-38.patch applied. Thanks Matthieu.
2014-10-06 21:05:27 +00:00
Antonin Descampe
7256e43c48 [trunk] fixed PDF crash in Chrome (fixes issue 362) 2014-10-06 21:05:21 +00:00
Antonin Descampe
a0a3af1dee [trunk] removed illegal character in comment 2014-10-03 19:52:20 +00:00
Antonin Descampe
48832d944f [trunk]fixes buffer overflow in t2.c
Update issue 390
Summary: check for negative-size params in code
Patch from Matthieu applied. Left open to apply this to other places in
code.
2014-10-03 10:15:28 +00:00
Antonin Descampe
06bd61b571 [trunk] c++-style comment removed (fixes issue 407) 2014-10-02 07:44:53 +00:00
Antonin Descampe
a1c754c737 [trunk] fixed warning from r2891 2014-10-01 12:11:43 +00:00
Antonin Descampe
fef1276901 [trunk] fixed bad use of case statement (fixes issue 381) 2014-09-30 12:19:13 +00:00
Antonin Descampe
45f33cdbd6 [trunk] check possible overflow on size in opj_t2_read_packet_data
Update issue 390
Labels: Priority-Critical
Should be rechecked with ASan and pdfium
2014-09-30 10:07:09 +00:00
Antonin Descampe
1acfa211ae [trunk] fixes heap-buffer-overflow in parse_cmdline_encoder
Fixes issue 403
Thanks Matthieu
2014-09-30 09:48:26 +00:00
Antonin Descampe
2f3fd1194e [trunk] prevent overflow in opj_t2_read_packet_header (update issue 389) 2014-09-30 09:26:44 +00:00
Antonin Descampe
f08af3ed82 [trunk] Ensure cblk->data pointer is correctly initialized (updates issue 391). Still need to check if it does not fail anymore with ASan. 2014-09-29 12:03:50 +00:00
Antonin Descampe
2720a1a405 [trunk] fixed tile numbering in output message (fixes issue 370) 2014-09-29 12:03:36 +00:00
Mathieu Malaterre
31fd8d3fe8 trunk: extend support for pdf2jp2 2014-09-19 15:48:48 +00:00
Antonin Descampe
6868ee373e added memory allocation checks (fixes issue 355) 2014-09-19 10:26:35 +00:00
Antonin Descampe
b9a247b559 fixes install name id on OSX builds (fixes issue 367) 2014-09-19 09:30:12 +00:00
Antonin Descampe
50a205d20f [trunk] improve memory management (fixes issue 359) 2014-09-16 15:48:04 +00:00
Antonin Descampe
b0072bf658 [trunk] allow compilation with MinGW32 (fixes issue 361) 2014-09-16 15:38:11 +00:00
Antonin Descampe
2c810567dd [trunk] Changed error to warning when no EOC found in codestream (fixes
issue 366)
2014-07-14 07:42:50 +00:00
Antonin Descampe
0a1a29a7fe [trunk] replaced malloc with opj_malloc. (Fixes issue 368). 2014-07-03 16:05:56 +00:00
Antonin Descampe
7d21871ed8 [trunk] fixes issue #357. MCT is automatically disabled when
subsamppling is detected.
2014-07-03 09:15:13 +00:00
Antonin Descampe
a38b97fae0 [trunk] moved comment marker setup from opj_compress to the library 2014-07-01 13:51:55 +00:00
30 changed files with 10012 additions and 833 deletions

10033
CHANGES

File diff suppressed because it is too large Load Diff

View File

@@ -146,6 +146,11 @@ if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
set(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
endif()
if (APPLE)
list(APPEND OPENJPEG_LIBRARY_PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${OPENJPEG_INSTALL_LIB_DIR}")
option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF)
endif()
#-----------------------------------------------------------------------------
# Big endian test:
include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)

4
NEWS
View File

@@ -2,7 +2,7 @@
OpenJPEG NEWS - user visible changes
====================================
Changes from OpenJPEG 2.0.0 to OpenJPEG 2.1.0
Changes from OpenJPEG 2.0.0 to OpenJPEG 2.X.X
----------------------------------------------
New Features:
@@ -39,7 +39,7 @@ Misc:
* OpenJPEG is now officialy conformant with JPEG 2000 Part-1
and will soon become official reference software at the
JPEG committee.
* Huge amount of bug fixes. See CHANGES for details.
* Huge amount of bug fixes. See CHANGES for details.
Changes from OpenJPEG 1.5.x to OpenJPEG 2.0.0

50
THANKS
View File

@@ -4,30 +4,32 @@ Many people have contributed to OpenJPEG by reporting problems, suggesting vario
or submitting actual code. Here is a list of these people. Help me keep
it complete and exempt of errors.
Winfried Szukalski
Vincent Torri
Bob Friesenhahn
Callum Lerwick
Dzonatas Sol
Julien Malik
Jerôme Fimes
Herve Drolon
Yannick Verschueren
Sebastien Lugan
Kaori Hagihara
Peter Wimmer
Francois-Olivier Devaux
Antonin Descampe
David Janssens
Pr. Benoit Macq
Luis Ibanez
Giuseppe Baruffa
Ben Boeckel
Aaron Boxer
David Burken
Matthieu Darbois
Rex Dieter
Herve Drolon
Antonin Descampe
Francois-Olivier Devaux
Parvatha Elangovan
Jerôme Fimes
Bob Friesenhahn
Kaori Hagihara
Luc Hermitte
Luis Ibanez
David Janssens
Hans Johnson
Callum Lerwick
Sebastien Lugan
Benoit Macq
Arnaud Maye
Julien Malik
Vincent Nicolas
Glenn Pearson
Giuseppe Baruffa
Arnaud Maye
Rex Dieter
David Burken
Parvatha Elangovan
Hans Johnson
Luc Hermitte
Dzonatas Sol
Winfried Szukalski
Vincent Torri
Yannick Verschueren
Peter Wimmer

View File

@@ -123,8 +123,8 @@ static void sycc422_to_rgb(opj_image_t *img)
{
int *d0, *d1, *d2, *r, *g, *b;
const int *y, *cb, *cr;
int maxw, maxh, max, offset, upb;
int i, j;
int maxw, maxh, max, offset, upb;
int i, j;
i = (int)img->comps[0].prec;
offset = 1<<(i - 1); upb = (1<<i)-1;
@@ -141,18 +141,22 @@ static void sycc422_to_rgb(opj_image_t *img)
d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
for(i=0; i < maxh; ++i)
{
for(j=0; j < maxw; j += 2)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
{
for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++cb; ++cr;
}
}
++y; ++r; ++g; ++b; ++cb; ++cr;
}
if (j < maxw) {
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++cb; ++cr;
}
}
free(img->comps[0].data); img->comps[0].data = d0;
free(img->comps[1].data); img->comps[1].data = d1;
free(img->comps[2].data); img->comps[2].data = d2;
@@ -192,31 +196,59 @@ static void sycc420_to_rgb(opj_image_t *img)
d1 = g = (int*)malloc(sizeof(int) * (size_t)max);
d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
for(i=0; i < maxh; i += 2)
{
ny = y + maxw;
nr = r + maxw; ng = g + maxw; nb = b + maxw;
for(i=0; (OPJ_UINT32)i < (maxh & ~(OPJ_UINT32)1); i += 2)
{
ny = y + maxw;
nr = r + maxw; ng = g + maxw; nb = b + maxw;
for(j=0; j < maxw; j += 2)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb;
++ny; ++nr; ++ng; ++nb;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb; ++cb; ++cr;
}
if(j < maxw)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb; ++cb; ++cr;
}
y += maxw; r += maxw; g += maxw; b += maxw;
}
if(i < maxh)
{
for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++cb; ++cr;
}
if(j < maxw)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
}
}
++ny; ++nr; ++ng; ++nb; ++cb; ++cr;
}
y += maxw; r += maxw; g += maxw; b += maxw;
}
free(img->comps[0].data); img->comps[0].data = d0;
free(img->comps[1].data); img->comps[1].data = d1;
free(img->comps[2].data); img->comps[2].data = d2;

View File

@@ -50,6 +50,13 @@ foreach(exe opj_decompress opj_compress opj_dump)
EXPORT OpenJPEGTargets
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
)
if(OPJ_USE_DSYMUTIL)
GET_TARGET_PROPERTY(EXE_LOCATION ${exe} LOCATION)
add_custom_command(TARGET ${exe} POST_BUILD
COMMAND "dsymutil" "${EXE_LOCATION}"
COMMENT "dsymutil ${EXE_LOCATION}"
DEPENDS ${exe})
endif()
endforeach()
if(BUILD_DOC)

View File

@@ -2988,10 +2988,13 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p
}
w = raw_cp->rawWidth;
h = raw_cp->rawHeight;
cmptparm = (opj_image_cmptparm_t*) malloc((size_t)numcomps * sizeof(opj_image_cmptparm_t));
cmptparm = (opj_image_cmptparm_t*) calloc(numcomps,sizeof(opj_image_cmptparm_t));
if (!cmptparm) {
fprintf(stderr, "Failed to allocate image components parameters !!\n");
fprintf(stderr,"Aborting\n");
return NULL;
}
/* initialize image components */
memset(&cmptparm[0], 0, (size_t)numcomps * sizeof(opj_image_cmptparm_t));
for(i = 0; i < numcomps; i++) {
cmptparm[i].prec = (OPJ_UINT32)raw_cp->rawBitDepth;
cmptparm[i].bpp = (OPJ_UINT32)raw_cp->rawBitDepth;
@@ -3018,7 +3021,7 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p
{
unsigned char value = 0;
for(compno = 0; compno < numcomps; compno++) {
int nloop = (w*h)/(raw_cp->rawComps[compno].dx*raw_cp->rawComps[compno].dx);
int nloop = (w*h)/(raw_cp->rawComps[compno].dx*raw_cp->rawComps[compno].dy);
for (i = 0; i < nloop; i++) {
if (!fread(&value, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");

View File

@@ -1500,6 +1500,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
}
}
/* If subsampled image is provided, automatically disable MCT */
if ( ((parameters->decod_format == RAW_DFMT) || (parameters->decod_format == RAWL_DFMT))
&& ( ((raw_cp->rawComp > 1 ) && ((raw_cp->rawComps[1].dx > 1) || (raw_cp->rawComps[1].dy > 1)))
|| ((raw_cp->rawComp > 2 ) && ((raw_cp->rawComps[2].dx > 1) || (raw_cp->rawComps[2].dy > 1)))
)) {
parameters->tcp_mct = 0;
}
return 0;
}
@@ -1572,22 +1580,6 @@ int main(int argc, char **argv) {
return 1;
}
/* Create comment for codestream */
if(parameters.cp_comment == NULL) {
const char comment[] = "Created by OpenJPEG version ";
const size_t clen = strlen(comment);
const char *version = opj_version();
/* UniPG>> */
#ifdef USE_JPWL
parameters.cp_comment = (char*)malloc(clen+strlen(version)+11);
sprintf(parameters.cp_comment,"%s%s with JPWL", comment, version);
#else
parameters.cp_comment = (char*)malloc(clen+strlen(version)+1);
sprintf(parameters.cp_comment,"%s%s", comment, version);
#endif
/* <<UniPG */
}
/* Read directory if necessary */
if(img_fol.set_imgdir==1){
num_images=get_num_images(img_fol.imgdirpath);
@@ -1792,8 +1784,7 @@ int main(int argc, char **argv) {
if( bSuccess && bUseTiles ) {
OPJ_BYTE *l_data;
OPJ_UINT32 l_data_size = 512*512*3;
l_data = (OPJ_BYTE*) malloc( l_data_size * sizeof(OPJ_BYTE));
memset(l_data, 0, l_data_size );
l_data = (OPJ_BYTE*) calloc( 1,l_data_size);
assert( l_data );
for (i=0;i<l_nb_tiles;++i) {
if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) {

View File

@@ -98,3 +98,13 @@ if(OPENJPEG_CPPCHECK)
COMMAND ${CPPCHECK_EXECUTABLE} -DWIN32 ${f})
endforeach()
endif()
if(OPJ_USE_DSYMUTIL)
if(BUILD_SHARED_LIBS)
GET_TARGET_PROPERTY(OPENJPEG_LIBRARY_LOCATION ${OPENJPEG_LIBRARY_NAME} LOCATION)
add_custom_command(TARGET ${OPENJPEG_LIBRARY_NAME} POST_BUILD
COMMAND "dsymutil" "${OPENJPEG_LIBRARY_LOCATION}"
COMMENT "dsymutil ${OPENJPEG_LIBRARY_LOCATION}"
DEPENDS ${OPENJPEG_LIBRARY_NAME})
endif()
endif()

View File

@@ -81,7 +81,7 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio);
OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
return OPJ_FALSE;
}
*bio->bp++ = (OPJ_BYTE)(bio->buf >> 8);
@@ -91,7 +91,7 @@ OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) {
OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
return OPJ_FALSE;
}
bio->buf |= *bio->bp++;

View File

@@ -151,12 +151,11 @@ void opj_read_float_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value)
opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size,OPJ_BOOL l_is_input)
{
opj_stream_private_t * l_stream = 00;
l_stream = (opj_stream_private_t*) opj_malloc(sizeof(opj_stream_private_t));
l_stream = (opj_stream_private_t*) opj_calloc(1,sizeof(opj_stream_private_t));
if (! l_stream) {
return 00;
}
memset(l_stream,0,sizeof(opj_stream_private_t));
l_stream->m_buffer_size = p_buffer_size;
l_stream->m_stored_data = (OPJ_BYTE *) opj_malloc(p_buffer_size);
if (! l_stream->m_stored_data) {

View File

@@ -571,6 +571,7 @@ OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1D
h.mem = (OPJ_INT32*)
opj_aligned_malloc(opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32));
if (! h.mem){
/* FIXME event manager error callback */
return OPJ_FALSE;
}
@@ -842,6 +843,10 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0);
h.wavelet = (opj_v4_t*) opj_aligned_malloc((opj_dwt_max_resolution(res, numres)+5) * sizeof(opj_v4_t));
if (!h.wavelet) {
/* FIXME event manager error callback */
return OPJ_FALSE;
}
v.wavelet = h.wavelet;
while( --numres) {

View File

@@ -39,22 +39,19 @@
opj_procedure_list_t * opj_procedure_list_create()
{
/* memory allocation */
opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_malloc(sizeof(opj_procedure_list_t));
opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t));
if (! l_validation)
{
return 00;
}
/* initialization */
memset(l_validation,0,sizeof(opj_procedure_list_t));
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
l_validation->m_procedures = (opj_procedure*)opj_malloc(
OPJ_VALIDATION_SIZE * sizeof(opj_procedure));
l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure));
if (! l_validation->m_procedures)
{
opj_free(l_validation);
return 00;
}
memset(l_validation->m_procedures,0,OPJ_VALIDATION_SIZE * sizeof(opj_procedure));
return l_validation;
}

View File

@@ -205,21 +205,19 @@ opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_c
OPJ_UINT32 compno;
opj_image_t *image = 00;
image = (opj_image_t*) opj_malloc(sizeof(opj_image_t));
image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t));
if (image)
{
memset(image,0,sizeof(opj_image_t));
image->color_space = clrspc;
image->numcomps = numcmpts;
/* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
if (!image->comps) {
opj_image_destroy(image);
return 00;
}
memset(image->comps,0,image->numcomps * sizeof(opj_image_comp_t));
/* create the individual image components */
for(compno = 0; compno < numcmpts; compno++) {

View File

@@ -1499,7 +1499,6 @@ OPJ_BOOL opj_j2k_check_poc_val( const opj_poc_t *p_pocs,
opj_event_msg(p_manager , EVT_ERROR, "Not enough memory for checking the poc values.\n");
return OPJ_FALSE;
}
memset(packet_array,0,step_l * p_num_layers* sizeof(OPJ_UINT32));
if (p_nb_pocs == 0) {
opj_free(packet_array);
@@ -2038,7 +2037,6 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
return OPJ_FALSE;
}
memset(l_image->comps,0,l_image->numcomps * sizeof(opj_image_comp_t));
l_img_comp = l_image->comps;
/* Read the component information */
@@ -2167,7 +2165,6 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
memset(l_cp->tcps,0,l_nb_tiles*sizeof(opj_tcp_t));
#ifdef USE_JPWL
if (l_cp->correct) {
@@ -2188,27 +2185,24 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
memset(p_j2k->m_specific_param.m_decoder.m_default_tcp->tccps ,0,l_image->numcomps*sizeof(opj_tccp_t));
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mct_records =
(opj_mct_data_t*)opj_malloc(OPJ_J2K_MCT_DEFAULT_NB_RECORDS * sizeof(opj_mct_data_t));
(opj_mct_data_t*)opj_calloc(OPJ_J2K_MCT_DEFAULT_NB_RECORDS ,sizeof(opj_mct_data_t));
if (! p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mct_records) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
memset(p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mct_records,0,OPJ_J2K_MCT_DEFAULT_NB_RECORDS * sizeof(opj_mct_data_t));
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_nb_max_mct_records = OPJ_J2K_MCT_DEFAULT_NB_RECORDS;
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mcc_records =
(opj_simple_mcc_decorrelation_data_t*)
opj_malloc(OPJ_J2K_MCC_DEFAULT_NB_RECORDS * sizeof(opj_simple_mcc_decorrelation_data_t));
opj_calloc(OPJ_J2K_MCC_DEFAULT_NB_RECORDS, sizeof(opj_simple_mcc_decorrelation_data_t));
if (! p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mcc_records) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
memset(p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mcc_records,0,OPJ_J2K_MCC_DEFAULT_NB_RECORDS * sizeof(opj_simple_mcc_decorrelation_data_t));
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_nb_max_mcc_records = OPJ_J2K_MCC_DEFAULT_NB_RECORDS;
/* set up default dc level shift */
@@ -2220,12 +2214,11 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
l_current_tile_param = l_cp->tcps;
for (i = 0; i < l_nb_tiles; ++i) {
l_current_tile_param->tccps = (opj_tccp_t*) opj_malloc(l_image->numcomps * sizeof(opj_tccp_t));
l_current_tile_param->tccps = (opj_tccp_t*) opj_calloc(l_image->numcomps, sizeof(opj_tccp_t));
if (l_current_tile_param->tccps == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
memset(l_current_tile_param->tccps,0,l_image->numcomps * sizeof(opj_tccp_t));
++l_current_tile_param;
}
@@ -2422,9 +2415,19 @@ static OPJ_BOOL opj_j2k_read_cod ( opj_j2k_t *p_j2k,
opj_read_bytes(p_header_data,&l_tcp->csty,1); /* Scod */
++p_header_data;
/* Make sure we know how to decode this */
if ((l_tcp->csty & ~(OPJ_UINT32)(J2K_CP_CSTY_PRT | J2K_CP_CSTY_SOP | J2K_CP_CSTY_EPH)) != 0U) {
opj_event_msg(p_manager, EVT_ERROR, "Unknown Scod value in COD marker\n");
return OPJ_FALSE;
}
opj_read_bytes(p_header_data,&l_tmp,1); /* SGcod (A) */
++p_header_data;
l_tcp->prg = (OPJ_PROG_ORDER) l_tmp;
/* Make sure progression order is valid */
if (l_tcp->prg > OPJ_CPRL ) {
opj_event_msg(p_manager, EVT_ERROR, "Unknown progression order in COD marker\n");
l_tcp->prg = OPJ_PROG_UNKNOWN;
}
opj_read_bytes(p_header_data,&l_tcp->numlayers,2); /* SGcod (B) */
p_header_data+=2;
@@ -3551,6 +3554,14 @@ OPJ_BOOL j2k_read_ppm_v3 (
/* First PPM marker */
if (l_Z_ppm == 0) {
if (l_cp->ppm_data != NULL) {
opj_event_msg(p_manager, EVT_ERROR, "Zppm O already processed. Found twice.\n");
opj_free(l_cp->ppm_data);
l_cp->ppm_data = NULL;
l_cp->ppm_buffer = NULL;
l_cp->ppm = 0; /* do not use PPM */
return OPJ_FALSE;
}
/* We need now at least the Nppm^0 element */
if (p_header_size < 4) {
opj_event_msg(p_manager, EVT_ERROR, "Error reading PPM marker\n");
@@ -3576,13 +3587,12 @@ OPJ_BOOL j2k_read_ppm_v3 (
l_cp->ppm_len = l_N_ppm;
l_cp->ppm_data_read = 0;
l_cp->ppm_data = (OPJ_BYTE *) opj_malloc(l_cp->ppm_len);
l_cp->ppm_data = (OPJ_BYTE *) opj_calloc(1,l_cp->ppm_len);
l_cp->ppm_buffer = l_cp->ppm_data;
if (l_cp->ppm_data == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read ppm marker\n");
return OPJ_FALSE;
}
memset(l_cp->ppm_data,0,l_cp->ppm_len);
l_cp->ppm_data_current = l_cp->ppm_data;
@@ -3649,6 +3659,15 @@ OPJ_BOOL j2k_read_ppm_v3 (
if (p_header_size)
{
if (p_header_size < 4) {
opj_free(l_cp->ppm_data);
l_cp->ppm_data = NULL;
l_cp->ppm_buffer = NULL; /* TODO: no need for a new local variable: ppm_buffer and ppm_data are enough */
l_cp->ppm_len = 0;
l_cp->ppm = 0;
opj_event_msg(p_manager, EVT_ERROR, "Error reading PPM marker\n");
return OPJ_FALSE;
}
opj_read_bytes(p_header_data,&l_N_ppm,4); /* N_ppm^i */
p_header_data+=4;
p_header_size-=4;
@@ -4128,6 +4147,10 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) {
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index =
(opj_tp_index_t*)opj_calloc(l_num_parts, sizeof(opj_tp_index_t));
if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n");
return OPJ_FALSE;
}
}
else {
opj_tp_index_t *new_tp_index = (opj_tp_index_t *) opj_realloc(
@@ -4135,7 +4158,7 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
if (! new_tp_index) {
opj_free(p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index);
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n");
return OPJ_FALSE;
}
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
@@ -4149,6 +4172,11 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index =
(opj_tp_index_t*)opj_calloc( p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps,
sizeof(opj_tp_index_t));
if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) {
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = 0;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n");
return OPJ_FALSE;
}
}
if ( l_current_part >= p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps ){
@@ -4161,7 +4189,7 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
opj_free(p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index);
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = NULL;
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = 0;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n");
return OPJ_FALSE;
}
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
@@ -4316,6 +4344,12 @@ OPJ_BOOL opj_j2k_read_sod (opj_j2k_t *p_j2k,
/* Patch to support new PHR data */
if (p_j2k->m_specific_param.m_decoder.m_sot_length) {
/* If we are here, we'll try to read the data after allocation */
/* Check enough bytes left in stream before allocation */
if ((OPJ_OFF_T)p_j2k->m_specific_param.m_decoder.m_sot_length > opj_stream_get_number_byte_left(p_stream)) {
opj_event_msg(p_manager, EVT_ERROR, "Tile part length size inconsistent with stream length\n");
return OPJ_FALSE;
}
if (! *l_current_data) {
/* LH: oddly enough, in this path, l_tile_len!=0.
* TODO: If this was consistant, we could simplify the code to only use realloc(), as realloc(0,...) default to malloc(0,...).
@@ -5853,12 +5887,11 @@ void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters)
opj_j2k_t* opj_j2k_create_compress(void)
{
opj_j2k_t *l_j2k = (opj_j2k_t*) opj_malloc(sizeof(opj_j2k_t));
opj_j2k_t *l_j2k = (opj_j2k_t*) opj_calloc(1,sizeof(opj_j2k_t));
if (!l_j2k) {
return NULL;
}
memset(l_j2k,0,sizeof(opj_j2k_t));
l_j2k->m_is_decoder = 0;
l_j2k->m_cp.m_is_decoder = 0;
@@ -6105,7 +6138,7 @@ OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, opj_ev
return OPJ_TRUE;
}
void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
OPJ_BOOL opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
opj_cparameters_t *parameters,
opj_image_t *image,
opj_event_mgr_t * p_manager)
@@ -6114,7 +6147,12 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
opj_cp_t *cp = 00;
if(!p_j2k || !parameters || ! image) {
return;
return OPJ_FALSE;
}
if ((parameters->numresolution <= 0) || (parameters->numresolution > OPJ_J2K_MAXRLVLS)) {
opj_event_msg(p_manager, EVT_ERROR, "Invalid number of resolutions : %d not in range [1,%d]\n", parameters->numresolution, OPJ_J2K_MAXRLVLS);
return OPJ_FALSE;
}
/* keep a link to cp so that we can destroy it later in j2k_destroy_compress */
@@ -6256,6 +6294,10 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
if (parameters->cp_fixed_alloc && parameters->cp_matrice) {
size_t array_size = (size_t)parameters->tcp_numlayers * (size_t)parameters->numresolution * 3 * sizeof(OPJ_INT32);
cp->m_specific_param.m_enc.m_matrice = (OPJ_INT32 *) opj_malloc(array_size);
if (!cp->m_specific_param.m_enc.m_matrice) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate copy of user encoding parameters matrix \n");
return OPJ_FALSE;
}
memcpy(cp->m_specific_param.m_enc.m_matrice, parameters->cp_matrice, array_size);
}
@@ -6269,11 +6311,36 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
/* comment string */
if(parameters->cp_comment) {
cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1);
if(cp->comment) {
strcpy(cp->comment, parameters->cp_comment);
}
}
cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1U);
if(!cp->comment) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate copy of comment string\n");
return OPJ_FALSE;
}
strcpy(cp->comment, parameters->cp_comment);
} else {
/* Create default comment for codestream */
const char comment[] = "Created by OpenJPEG version ";
const size_t clen = strlen(comment);
const char *version = opj_version();
/* UniPG>> */
#ifdef USE_JPWL
cp->comment = (char*)opj_malloc(clen+strlen(version)+11);
if(!cp->comment) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate comment string\n");
return OPJ_FALSE;
}
sprintf(cp->comment,"%s%s with JPWL", comment, version);
#else
cp->comment = (char*)opj_malloc(clen+strlen(version)+1);
if(!cp->comment) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate comment string\n");
return OPJ_FALSE;
}
sprintf(cp->comment,"%s%s", comment, version);
#endif
/* <<UniPG */
}
/*
calculate other encoding parameters
@@ -6351,6 +6418,10 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
/* initialize the mutiple tiles */
/* ---------------------------- */
cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
if (!cp->tcps) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate tile coding parameters\n");
return OPJ_FALSE;
}
if (parameters->numpocs) {
/* initialisation of POC */
opj_j2k_check_poc_val(parameters->POC,parameters->numpocs, (OPJ_UINT32)parameters->numresolution, image->numcomps, (OPJ_UINT32)parameters->tcp_numlayers, p_manager);
@@ -6408,24 +6479,54 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
}
tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t));
if (!tcp->tccps) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate tile component coding parameters\n");
return OPJ_FALSE;
}
if (parameters->mct_data) {
OPJ_UINT32 lMctSize = image->numcomps * image->numcomps * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
OPJ_FLOAT32 * lTmpBuf = (OPJ_FLOAT32*)opj_malloc(lMctSize);
OPJ_INT32 * l_dc_shift = (OPJ_INT32 *) ((OPJ_BYTE *) parameters->mct_data + lMctSize);
if (!lTmpBuf) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate temp buffer\n");
return OPJ_FALSE;
}
tcp->mct = 2;
tcp->m_mct_coding_matrix = (OPJ_FLOAT32*)opj_malloc(lMctSize);
if (! tcp->m_mct_coding_matrix) {
opj_free(lTmpBuf);
lTmpBuf = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate encoder MCT coding matrix \n");
return OPJ_FALSE;
}
memcpy(tcp->m_mct_coding_matrix,parameters->mct_data,lMctSize);
memcpy(lTmpBuf,parameters->mct_data,lMctSize);
tcp->m_mct_decoding_matrix = (OPJ_FLOAT32*)opj_malloc(lMctSize);
assert(opj_matrix_inversion_f(lTmpBuf,(tcp->m_mct_decoding_matrix),image->numcomps));
if (! tcp->m_mct_decoding_matrix) {
opj_free(lTmpBuf);
lTmpBuf = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate encoder MCT decoding matrix \n");
return OPJ_FALSE;
}
if(opj_matrix_inversion_f(lTmpBuf,(tcp->m_mct_decoding_matrix),image->numcomps) == OPJ_FALSE) {
opj_free(lTmpBuf);
lTmpBuf = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Failed to inverse encoder MCT decoding matrix \n");
return OPJ_FALSE;
}
tcp->mct_norms = (OPJ_FLOAT64*)
opj_malloc(image->numcomps * sizeof(OPJ_FLOAT64));
if (! tcp->mct_norms) {
opj_free(lTmpBuf);
lTmpBuf = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate encoder MCT norms \n");
return OPJ_FALSE;
}
opj_calculate_norms(tcp->mct_norms,image->numcomps,tcp->m_mct_decoding_matrix);
opj_free(lTmpBuf);
@@ -6434,9 +6535,22 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
tccp->m_dc_level_shift = l_dc_shift[i];
}
opj_j2k_setup_mct_encoding(tcp,image);
if (opj_j2k_setup_mct_encoding(tcp,image) == OPJ_FALSE) {
/* free will be handled by opj_j2k_destroy */
opj_event_msg(p_manager, EVT_ERROR, "Failed to setup j2k mct encoding\n");
return OPJ_FALSE;
}
}
else {
if(tcp->mct==1 && image->numcomps == 3) { /* RGB->YCC MCT is enabled */
if ((image->comps[0].dx != image->comps[1].dx) ||
(image->comps[0].dx != image->comps[2].dx) ||
(image->comps[0].dy != image->comps[1].dy) ||
(image->comps[0].dy != image->comps[2].dy)) {
opj_event_msg(p_manager, EVT_WARNING, "Cannot perform MCT on components with different sizes. Disabling MCT.\n");
tcp->mct = 0;
}
}
for (i = 0; i < image->numcomps; i++) {
opj_tccp_t *tccp = &tcp->tccps[i];
opj_image_comp_t * l_comp = &(image->comps[i]);
@@ -6523,6 +6637,7 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
opj_free(parameters->mct_data);
parameters->mct_data = 00;
}
return OPJ_TRUE;
}
static OPJ_BOOL opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len)
@@ -6915,6 +7030,15 @@ OPJ_BOOL opj_j2k_encoding_validation ( opj_j2k_t * p_j2k,
/* make sure a validation list is present */
l_is_valid &= (p_j2k->m_validation_list != 00);
/* ISO 15444-1:2004 states between 1 & 33 (0 -> 32) */
/* 33 (32) would always fail the 2 checks below (if a cast to 64bits was done) */
/* 32 (31) would always fail the 2 checks below (if a cast to 64bits was done) */
/* FIXME Shall we change OPJ_J2K_MAXRLVLS to 31 ? */
if ((p_j2k->m_cp.tcps->tccps->numresolutions <= 0) || (p_j2k->m_cp.tcps->tccps->numresolutions > 31)) {
opj_event_msg(p_manager, EVT_ERROR, "Number of resolutions is too high in comparison to the size of tiles\n");
return OPJ_FALSE;
}
if ((p_j2k->m_cp.tdx) < (OPJ_UINT32) (1 << p_j2k->m_cp.tcps->tccps->numresolutions)) {
opj_event_msg(p_manager, EVT_ERROR, "Number of resolutions is too high in comparison to the size of tiles\n");
return OPJ_FALSE;
@@ -6966,6 +7090,9 @@ OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k,
OPJ_UINT32 l_current_marker;
OPJ_UINT32 l_marker_size;
const opj_dec_memory_marker_handler_t * l_marker_handler = 00;
OPJ_BOOL l_has_siz = 0;
OPJ_BOOL l_has_cod = 0;
OPJ_BOOL l_has_qcd = 0;
/* preconditions */
assert(p_stream != 00);
@@ -7015,6 +7142,19 @@ OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k,
l_marker_handler = opj_j2k_get_marker_handler(l_current_marker);
}
if (l_marker_handler->id == J2K_MS_SIZ) {
/* Mark required SIZ marker as found */
l_has_siz = 1;
}
if (l_marker_handler->id == J2K_MS_COD) {
/* Mark required COD marker as found */
l_has_cod = 1;
}
if (l_marker_handler->id == J2K_MS_QCD) {
/* Mark required QCD marker as found */
l_has_qcd = 1;
}
/* Check if the marker is known and if it is the right place to find it */
if (! (p_j2k->m_specific_param.m_decoder.m_state & l_marker_handler->states) ) {
opj_event_msg(p_manager, EVT_ERROR, "Marker is not compliant with its position\n");
@@ -7077,6 +7217,19 @@ OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k,
opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_current_marker,2);
}
if (l_has_siz == 0) {
opj_event_msg(p_manager, EVT_ERROR, "required SIZ marker not found in main header\n");
return OPJ_FALSE;
}
if (l_has_cod == 0) {
opj_event_msg(p_manager, EVT_ERROR, "required COD marker not found in main header\n");
return OPJ_FALSE;
}
if (l_has_qcd == 0) {
opj_event_msg(p_manager, EVT_ERROR, "required QCD marker not found in main header\n");
return OPJ_FALSE;
}
opj_event_msg(p_manager, EVT_INFO, "Main header has been correctly decoded.\n");
/* Position of the last element if the main header */
@@ -7513,6 +7666,12 @@ OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k,
/* Read 2 bytes from the buffer as the marker size */
opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_marker_size,2);
/* Check marker size (does not include marker ID but includes marker size) */
if (l_marker_size < 2) {
opj_event_msg(p_manager, EVT_ERROR, "Inconsistent marker size\n");
return OPJ_FALSE;
}
/* cf. https://code.google.com/p/openjpeg/issues/detail?id=226 */
if (l_current_marker == 0x8080 && opj_stream_get_number_byte_left(p_stream) == 0) {
p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC;
@@ -7537,7 +7696,14 @@ OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k,
/* Check if the marker size is compatible with the header data size */
if (l_marker_size > p_j2k->m_specific_param.m_decoder.m_header_data_size) {
OPJ_BYTE *new_header_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_decoder.m_header_data, l_marker_size);
OPJ_BYTE *new_header_data = NULL;
/* If we are here, this means we consider this marker as known & we will read it */
/* Check enough bytes left in stream before allocation */
if ((OPJ_OFF_T)l_marker_size > opj_stream_get_number_byte_left(p_stream)) {
opj_event_msg(p_manager, EVT_ERROR, "Marker size inconsistent with stream length\n");
return OPJ_FALSE;
}
new_header_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_decoder.m_header_data, l_marker_size);
if (! new_header_data) {
opj_free(p_j2k->m_specific_param.m_decoder.m_header_data);
p_j2k->m_specific_param.m_decoder.m_header_data = NULL;
@@ -7673,7 +7839,7 @@ OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k,
}
opj_event_msg(p_manager, EVT_INFO, "Header of tile %d / %d has been read.\n",
p_j2k->m_current_tile_number, (p_j2k->m_cp.th * p_j2k->m_cp.tw) - 1);
p_j2k->m_current_tile_number+1, (p_j2k->m_cp.th * p_j2k->m_cp.tw));
*p_tile_index = p_j2k->m_current_tile_number;
*p_go_on = OPJ_TRUE;
@@ -7758,13 +7924,13 @@ OPJ_BOOL opj_j2k_decode_tile ( opj_j2k_t * p_j2k,
p_j2k->m_specific_param.m_decoder.m_state = 0x0100;/*FIXME J2K_DEC_STATE_EOC;*/
}
else if (l_current_marker != J2K_MS_SOT)
{
opj_event_msg(p_manager, EVT_ERROR, "Stream too short, expected SOT\n");
{
if(opj_stream_get_number_byte_left(p_stream) == 0) {
p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC;
opj_event_msg(p_manager, EVT_WARNING, "Stream does not end with EOC\n");
return OPJ_TRUE;
}
opj_event_msg(p_manager, EVT_ERROR, "Stream too short, expected SOT\n");
return OPJ_FALSE;
}
}
@@ -8192,23 +8358,21 @@ OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k,
opj_j2k_t* opj_j2k_create_decompress(void)
{
opj_j2k_t *l_j2k = (opj_j2k_t*) opj_malloc(sizeof(opj_j2k_t));
opj_j2k_t *l_j2k = (opj_j2k_t*) opj_calloc(1,sizeof(opj_j2k_t));
if (!l_j2k) {
return 00;
}
memset(l_j2k,0,sizeof(opj_j2k_t));
l_j2k->m_is_decoder = 1;
l_j2k->m_cp.m_is_decoder = 1;
l_j2k->m_specific_param.m_decoder.m_default_tcp = (opj_tcp_t*) opj_malloc(sizeof(opj_tcp_t));
l_j2k->m_specific_param.m_decoder.m_default_tcp = (opj_tcp_t*) opj_calloc(1,sizeof(opj_tcp_t));
if (!l_j2k->m_specific_param.m_decoder.m_default_tcp) {
opj_j2k_destroy(l_j2k);
return 00;
}
memset(l_j2k->m_specific_param.m_decoder.m_default_tcp,0,sizeof(opj_tcp_t));
l_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE *) opj_malloc(OPJ_J2K_DEFAULT_HEADER_SIZE);
l_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE *) opj_calloc(1,OPJ_J2K_DEFAULT_HEADER_SIZE);
if (! l_j2k->m_specific_param.m_decoder.m_header_data) {
opj_j2k_destroy(l_j2k);
return 00;
@@ -8222,16 +8386,11 @@ opj_j2k_t* opj_j2k_create_decompress(void)
/* codestream index creation */
l_j2k->cstr_index = opj_j2k_create_cstr_index();
/*(opj_codestream_index_t*) opj_malloc(sizeof(opj_codestream_index_t));
if (!l_j2k->cstr_index){
opj_j2k_destroy(l_j2k);
return NULL;
return 00;
}
l_j2k->cstr_index->marker = (opj_marker_info_t*) opj_malloc(100 * sizeof(opj_marker_info_t));
*/
/* validation list creation */
l_j2k->m_validation_list = opj_procedure_list_create();
if (! l_j2k->m_validation_list) {
@@ -9646,6 +9805,10 @@ OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k,
assert(p_manager != 00);
p_j2k->m_private_image = opj_image_create0();
if (! p_j2k->m_private_image) {
opj_event_msg(p_manager, EVT_ERROR, "Failed to allocate image header." );
return OPJ_FALSE;
}
opj_copy_image_header(p_image, p_j2k->m_private_image);
/* TODO_MSD: Find a better way */

View File

@@ -594,7 +594,7 @@ void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters);
opj_j2k_t* opj_j2k_create_compress(void);
void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
OPJ_BOOL opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
opj_cparameters_t *parameters,
opj_image_t *image,
opj_event_mgr_t * p_manager);

View File

@@ -537,12 +537,11 @@ OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2,
p_image_header_data += 2;
/* allocate memory for components */
jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps, sizeof(opj_jp2_comps_t));
if (jp2->comps == 0) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle image header (ihdr)\n");
return OPJ_FALSE;
}
memset(jp2->comps,0,jp2->numcomps * sizeof(opj_jp2_comps_t));
opj_read_bytes(p_image_header_data,&(jp2->bpc),1); /* BPC */
++ p_image_header_data;
@@ -574,11 +573,10 @@ OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2,
assert(p_nb_bytes_written != 00);
/* default image header is 22 bytes wide */
l_ihdr_data = (OPJ_BYTE *) opj_malloc(22);
l_ihdr_data = (OPJ_BYTE *) opj_calloc(1,22);
if (l_ihdr_data == 00) {
return 00;
}
memset(l_ihdr_data,0,22);
l_current_ihdr_ptr = l_ihdr_data;
@@ -627,11 +625,10 @@ OPJ_BYTE * opj_jp2_write_bpcc( opj_jp2_t *jp2,
assert(jp2 != 00);
assert(p_nb_bytes_written != 00);
l_bpcc_data = (OPJ_BYTE *) opj_malloc(l_bpcc_size);
l_bpcc_data = (OPJ_BYTE *) opj_calloc(1,l_bpcc_size);
if (l_bpcc_data == 00) {
return 00;
}
memset(l_bpcc_data,0,l_bpcc_size);
l_current_bpcc_ptr = l_bpcc_data;
@@ -709,11 +706,10 @@ OPJ_BYTE * opj_jp2_write_colr( opj_jp2_t *jp2,
return 00;
}
l_colr_data = (OPJ_BYTE *) opj_malloc(l_colr_size);
l_colr_data = (OPJ_BYTE *) opj_calloc(1,l_colr_size);
if (l_colr_data == 00) {
return 00;
}
memset(l_colr_data,0,l_colr_size);
l_current_colr_ptr = l_colr_data;
@@ -768,6 +764,12 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
if (color->jp2_cdef) {
opj_jp2_cdef_info_t *info = color->jp2_cdef->info;
OPJ_UINT16 n = color->jp2_cdef->n;
OPJ_UINT32 nr_channels = image->numcomps; /* FIXME image->numcomps == jp2->numcomps before color is applied ??? */
/* cdef applies to cmap channels if any */
if (color->jp2_pclr && color->jp2_pclr->cmap) {
nr_channels = (OPJ_UINT32)color->jp2_pclr->nr_channels;
}
for (i = 0; i < n; i++) {
if (info[i].cn >= image->numcomps) {
@@ -779,6 +781,22 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
return OPJ_FALSE;
}
}
/* issue 397 */
/* ISO 15444-1 states that if cdef is present, it shall contain a complete list of channel definitions. */
while (nr_channels > 0)
{
for(i = 0; i < n; ++i) {
if ((OPJ_UINT32)info[i].cn == (nr_channels - 1U)) {
break;
}
}
if (i == n) {
opj_event_msg(p_manager, EVT_ERROR, "Incomplete channel definitions.\n");
return OPJ_FALSE;
}
--nr_channels;
}
}
/* testcases 451.pdf.SIGSEGV.f4c.3723, 451.pdf.SIGSEGV.5b5.3723 and
@@ -859,7 +877,11 @@ void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
old_comps = image->comps;
new_comps = (opj_image_comp_t*)
opj_malloc(nr_channels * sizeof(opj_image_comp_t));
if (!new_comps) {
/* FIXME no error code for opj_jp2_apply_pclr */
/* FIXME event manager error callback */
return;
}
for(i = 0; i < nr_channels; ++i) {
pcol = cmap[i].pcol; cmp = cmap[i].cmp;
@@ -875,6 +897,13 @@ void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
/* Palette mapping: */
new_comps[i].data = (OPJ_INT32*)
opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(OPJ_INT32));
if (!new_comps[i].data) {
opj_free(new_comps);
new_comps = NULL;
/* FIXME no error code for opj_jp2_apply_pclr */
/* FIXME event manager error callback */
return;
}
new_comps[i].prec = channel_size[i];
new_comps[i].sgnd = channel_sign[i];
}
@@ -1010,7 +1039,7 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2,
if (bytes_to_read > sizeof(OPJ_UINT32))
bytes_to_read = sizeof(OPJ_UINT32);
if ((ptrdiff_t)p_pclr_header_size < p_pclr_header_data - orig_header_data + (ptrdiff_t)bytes_to_read)
if ((ptrdiff_t)p_pclr_header_size < (ptrdiff_t)(p_pclr_header_data - orig_header_data) + (ptrdiff_t)bytes_to_read)
return OPJ_FALSE;
opj_read_bytes(p_pclr_header_data, &l_value , bytes_to_read); /* Cji */
@@ -1255,13 +1284,12 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3;
jp2->color.icc_profile_len = (OPJ_UINT32)icc_len;
jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_malloc((size_t)icc_len);
jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_calloc(1,(size_t)icc_len);
if (!jp2->color.icc_profile_buf)
{
jp2->color.icc_profile_len = 0;
return OPJ_FALSE;
}
memset(jp2->color.icc_profile_buf, 0, (size_t)icc_len * sizeof(OPJ_BYTE));
for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value)
{
@@ -1274,7 +1302,7 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
}
else if (jp2->meth > 2)
{
/* ISO/IEC 15444-1:2004 (E), Table I.9 <20> Legal METH values:
/* ISO/IEC 15444-1:2004 (E), Table I.9 Legal METH values:
conforming JP2 reader shall ignore the entire Colour Specification box.*/
opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a regular value (%d), "
"so we will ignore the entire Colour Specification box. \n", jp2->meth);
@@ -1448,15 +1476,13 @@ OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2,
assert(jp2 != 00);
assert(p_manager != 00);
l_ftyp_data = (OPJ_BYTE *) opj_malloc(l_ftyp_size);
l_ftyp_data = (OPJ_BYTE *) opj_calloc(1,l_ftyp_size);
if (l_ftyp_data == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle ftyp data\n");
return OPJ_FALSE;
}
memset(l_ftyp_data,0,l_ftyp_size);
l_current_data_ptr = l_ftyp_data;
opj_write_bytes(l_current_data_ptr, l_ftyp_size,4); /* box size */
@@ -1567,7 +1593,7 @@ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters)
/* JP2 encoder interface */
/* ----------------------------------------------------------------------- */
void opj_jp2_setup_encoder( opj_jp2_t *jp2,
OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
opj_cparameters_t *parameters,
opj_image_t *image,
opj_event_mgr_t * p_manager)
@@ -1577,7 +1603,7 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
OPJ_UINT32 sign;
if(!jp2 || !parameters || !image)
return;
return OPJ_FALSE;
/* setup the J2K codec */
/* ------------------- */
@@ -1585,10 +1611,12 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
/* Check if number of components respects standard */
if (image->numcomps < 1 || image->numcomps > 16384) {
opj_event_msg(p_manager, EVT_ERROR, "Invalid number of components specified while setting up JP2 encoder\n");
return;
return OPJ_FALSE;
}
opj_j2k_setup_encoder(jp2->j2k, parameters, image, p_manager );
if (opj_j2k_setup_encoder(jp2->j2k, parameters, image, p_manager ) == OPJ_FALSE) {
return OPJ_FALSE;
}
/* setup the JP2 codec */
/* ------------------- */
@@ -1599,22 +1627,23 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
jp2->minversion = 0; /* MinV */
jp2->numcl = 1;
jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
if (!jp2->cl){
jp2->cl = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
return;
}
if (!jp2->cl){
jp2->cl = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
return OPJ_FALSE;
}
jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */
/* Image Header box */
jp2->numcomps = image->numcomps; /* NC */
jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
if (!jp2->comps) {
jp2->comps = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
return;
}
if (!jp2->comps) {
jp2->comps = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
/* Memory of jp2->cl will be freed by opj_jp2_destroy */
return OPJ_FALSE;
}
jp2->h = image->y1 - image->y0; /* HEIGHT */
jp2->w = image->x1 - image->x0; /* WIDTH */
@@ -1657,6 +1686,8 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
jp2->approx = 0; /* APPROX */
jp2->jpip_on = parameters->jpip_on;
return OPJ_TRUE;
}
OPJ_BOOL opj_jp2_encode(opj_jp2_t *jp2,
@@ -1807,13 +1838,12 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
assert(jp2 != 00);
assert(p_manager != 00);
l_current_data = (OPJ_BYTE*)opj_malloc(l_last_data_size);
l_current_data = (OPJ_BYTE*)opj_calloc(1,l_last_data_size);
if (l_current_data == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle jpeg2000 file header\n");
return OPJ_FALSE;
}
memset(l_current_data, 0 , l_last_data_size);
while (opj_jp2_read_boxhdr(&box,&l_nb_bytes_read,stream,p_manager)) {
/* is it the codestream box ? */
@@ -1835,7 +1865,7 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
return OPJ_FALSE;
}
/* testcase 1851.pdf.SIGSEGV.ce9.948 */
else if (box.length < l_nb_bytes_read) {
else if (box.length < l_nb_bytes_read) {
opj_event_msg(p_manager, EVT_ERROR, "invalid box size %d (%x)\n", box.length, box.type);
opj_free(l_current_data);
return OPJ_FALSE;
@@ -1845,6 +1875,12 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
l_current_data_size = box.length - l_nb_bytes_read;
if (l_current_handler != 00) {
if ((OPJ_OFF_T)l_current_data_size > opj_stream_get_number_byte_left(stream)) {
/* do not even try to malloc if we can't read */
opj_event_msg(p_manager, EVT_ERROR, "Invalid box size %d for box '%c%c%c%c'. Need %d bytes, %d bytes remaining \n", box.length, (OPJ_BYTE)(box.type>>24), (OPJ_BYTE)(box.type>>16), (OPJ_BYTE)(box.type>>8), (OPJ_BYTE)(box.type>>0), l_current_data_size, (OPJ_UINT32)opj_stream_get_number_byte_left(stream));
opj_free(l_current_data);
return OPJ_FALSE;
}
if (l_current_data_size > l_last_data_size) {
OPJ_BYTE* new_current_data = (OPJ_BYTE*)opj_realloc(l_current_data,l_current_data_size);
if (!new_current_data) {
@@ -2083,12 +2119,11 @@ static OPJ_BOOL opj_jp2_read_ftyp( opj_jp2_t *jp2,
/* div by 4 */
jp2->numcl = l_remaining_bytes >> 2;
if (jp2->numcl) {
jp2->cl = (OPJ_UINT32 *) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
jp2->cl = (OPJ_UINT32 *) opj_calloc(jp2->numcl, sizeof(OPJ_UINT32));
if (jp2->cl == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory with FTYP Box\n");
return OPJ_FALSE;
}
memset(jp2->cl,0,jp2->numcl * sizeof(OPJ_UINT32));
}
for (i = 0; i < jp2->numcl; ++i)
@@ -2157,6 +2192,7 @@ static OPJ_BOOL opj_jp2_read_jp2h( opj_jp2_t *jp2,
OPJ_UINT32 l_box_size=0, l_current_data_size = 0;
opj_jp2_box_t box;
const opj_jp2_header_handler_t * l_current_handler;
OPJ_BOOL l_has_ihdr = 0;
/* preconditions */
assert(p_header_data != 00);
@@ -2197,10 +2233,19 @@ static OPJ_BOOL opj_jp2_read_jp2h( opj_jp2_t *jp2,
jp2->jp2_img_state |= JP2_IMG_STATE_UNKNOWN;
}
if (box.type == JP2_IHDR) {
l_has_ihdr = 1;
}
p_header_data += l_current_data_size;
p_header_size -= box.length;
}
if (l_has_ihdr == 0) {
opj_event_msg(p_manager, EVT_ERROR, "Stream error while reading JP2 Header box: no 'ihdr' box.\n");
return OPJ_FALSE;
}
jp2->jp2_state |= JP2_STATE_HEADER;
return OPJ_TRUE;
@@ -2269,7 +2314,10 @@ OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box,
opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n");
return OPJ_FALSE;
}
if (box->length < *p_number_bytes_read) {
opj_event_msg(p_manager, EVT_ERROR, "Box length is inconsistent.\n");
return OPJ_FALSE;
}
return OPJ_TRUE;
}
@@ -2531,9 +2579,8 @@ OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
opj_jp2_t* opj_jp2_create(OPJ_BOOL p_is_decoder)
{
opj_jp2_t *jp2 = (opj_jp2_t*)opj_malloc(sizeof(opj_jp2_t));
opj_jp2_t *jp2 = (opj_jp2_t*)opj_calloc(1,sizeof(opj_jp2_t));
if (jp2) {
memset(jp2,0,sizeof(opj_jp2_t));
/* create the J2K codec */
if (! p_is_decoder) {

View File

@@ -278,8 +278,9 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
* @param parameters compression parameters
* @param image input filled image
* @param p_manager FIXME DOC
* @return OPJ_TRUE if successful, OPJ_FALSE otherwise
*/
void opj_jp2_setup_encoder( opj_jp2_t *jp2,
OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
opj_cparameters_t *parameters,
opj_image_t *image,
opj_event_mgr_t * p_manager);

View File

@@ -362,7 +362,9 @@ static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) {
opj_mqc_t* opj_mqc_create(void) {
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
#ifdef MQC_PERF_OPT
mqc->buffer = NULL;
if (mqc) {
mqc->buffer = NULL;
}
#endif
return mqc;
}
@@ -370,7 +372,9 @@ opj_mqc_t* opj_mqc_create(void) {
void opj_mqc_destroy(opj_mqc_t *mqc) {
if(mqc) {
#ifdef MQC_PERF_OPT
opj_free(mqc->buffer);
if (mqc->buffer) {
opj_free(mqc->buffer);
}
#endif
opj_free(mqc);
}

View File

@@ -132,7 +132,7 @@ static OPJ_BOOL opj_seek_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
#ifdef _WIN32
#ifndef OPJ_STATIC
BOOL APIENTRY
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
OPJ_ARG_NOT_USED(lpReserved);
OPJ_ARG_NOT_USED(hModule);
@@ -169,7 +169,6 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
if (!l_codec){
return 00;
}
memset(l_codec, 0, sizeof(opj_codec_private_t));
l_codec->is_decompressor = 1;
@@ -546,7 +545,6 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
if (!l_codec) {
return 00;
}
memset(l_codec, 0, sizeof(opj_codec_private_t));
l_codec->is_decompressor = 0;
@@ -574,7 +572,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_j2k_destroy;
l_codec->m_codec_data.m_compression.opj_setup_encoder = (void (*) ( void *,
l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL (*) ( void *,
opj_cparameters_t *,
struct opj_image *,
struct opj_event_mgr * )) opj_j2k_setup_encoder;
@@ -611,7 +609,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_jp2_destroy;
l_codec->m_codec_data.m_compression.opj_setup_encoder = (void (*) ( void *,
l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL (*) ( void *,
opj_cparameters_t *,
struct opj_image *,
struct opj_event_mgr * )) opj_jp2_setup_encoder;

View File

@@ -142,10 +142,10 @@ typedef struct opj_codec_private
void (* opj_destroy) (void * p_codec);
void (* opj_setup_encoder) ( void * p_codec,
opj_cparameters_t * p_param,
struct opj_image * p_image,
struct opj_event_mgr * p_manager);
OPJ_BOOL (* opj_setup_encoder) ( void * p_codec,
opj_cparameters_t * p_param,
struct opj_image * p_image,
struct opj_event_mgr * p_manager);
} m_compression;
} m_codec_data;
/** FIXME DOC*/

View File

@@ -815,7 +815,6 @@ opj_pi_iterator_t * opj_pi_create( const opj_image_t *image,
if (!l_pi) {
return NULL;
}
memset(l_pi,0,l_poc_bound * sizeof(opj_pi_iterator_t));
l_current_pi = l_pi;
for (pino = 0; pino < l_poc_bound ; ++pino) {
@@ -827,21 +826,19 @@ opj_pi_iterator_t * opj_pi_create( const opj_image_t *image,
}
l_current_pi->numcomps = image->numcomps;
memset(l_current_pi->comps,0,image->numcomps * sizeof(opj_pi_comp_t));
for (compno = 0; compno < image->numcomps; ++compno) {
opj_pi_comp_t *comp = &l_current_pi->comps[compno];
tccp = &tcp->tccps[compno];
comp->resolutions = (opj_pi_resolution_t*) opj_malloc(tccp->numresolutions * sizeof(opj_pi_resolution_t));
comp->resolutions = (opj_pi_resolution_t*) opj_calloc(tccp->numresolutions, sizeof(opj_pi_resolution_t));
if (!comp->resolutions) {
opj_pi_destroy(l_pi, l_poc_bound);
return 00;
}
comp->numresolutions = tccp->numresolutions;
memset(comp->resolutions,0,tccp->numresolutions * sizeof(opj_pi_resolution_t));
}
++l_current_pi;
}
@@ -1108,7 +1105,8 @@ OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos,
break;
case 'P':
switch(tcp->prg){
case OPJ_LRCP||OPJ_RLCP:
case OPJ_LRCP: /* fall through */
case OPJ_RLCP:
if(tcp->prc_t == tcp->prcE){
if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){
return OPJ_TRUE;
@@ -1242,7 +1240,6 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
opj_pi_destroy(l_pi, l_bound);
return 00;
}
memset(l_current_pi->include,0, (l_tcp->numlayers + 1) * l_step_l* sizeof(OPJ_INT16));
/* special treatment for the first packet iterator */
l_current_comp = l_current_pi->comps;
@@ -1439,7 +1436,6 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
opj_pi_destroy(l_pi, l_bound);
return 00;
}
memset(l_current_pi->include,0,l_tcp->numlayers * l_step_l* sizeof(OPJ_INT16));
/* special treatment for the first packet iterator*/
l_current_comp = l_current_pi->comps;

View File

@@ -1170,6 +1170,7 @@ OPJ_BOOL opj_t1_allocate_buffers(
opj_aligned_free(t1->data);
t1->data = (OPJ_INT32*) opj_aligned_malloc(datasize * sizeof(OPJ_INT32));
if(!t1->data){
/* FIXME event manager error callback */
return OPJ_FALSE;
}
t1->datasize=datasize;
@@ -1183,6 +1184,7 @@ OPJ_BOOL opj_t1_allocate_buffers(
opj_aligned_free(t1->flags);
t1->flags = (opj_flag_t*) opj_aligned_malloc(flagssize * sizeof(opj_flag_t));
if(!t1->flags){
/* FIXME event manager error callback */
return OPJ_FALSE;
}
t1->flagssize=flagssize;
@@ -1207,11 +1209,10 @@ opj_t1_t* opj_t1_create()
{
opj_t1_t *l_t1 = 00;
l_t1 = (opj_t1_t*) opj_malloc(sizeof(opj_t1_t));
l_t1 = (opj_t1_t*) opj_calloc(1,sizeof(opj_t1_t));
if (!l_t1) {
return 00;
}
memset(l_t1,0,sizeof(opj_t1_t));
/* create MQC and RAW handles */
l_t1->mqc = opj_mqc_create();

View File

@@ -242,6 +242,11 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
/* TODO MSD : check why this function cannot fail (cf. v1) */
opj_pi_create_encode(l_pi, l_cp,p_tile_no,poc,l_tp_num,p_tp_pos,p_t2_mode);
if (l_current_pi->poc.prg == OPJ_PROG_UNKNOWN) {
/* TODO ADE : add an error */
opj_pi_destroy(l_pi, l_nb_pocs);
return OPJ_FALSE;
}
while (opj_pi_next(l_current_pi)) {
if (l_current_pi->layno < p_maxlayers) {
l_nb_bytes = 0;
@@ -274,7 +279,11 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
opj_pi_create_encode(l_pi, l_cp,p_tile_no,p_pino,p_tp_num,p_tp_pos,p_t2_mode);
l_current_pi = &l_pi[p_pino];
if (l_current_pi->poc.prg == OPJ_PROG_UNKNOWN) {
/* TODO ADE : add an error */
opj_pi_destroy(l_pi, l_nb_pocs);
return OPJ_FALSE;
}
while (opj_pi_next(l_current_pi)) {
if (l_current_pi->layno < p_maxlayers) {
l_nb_bytes=0;
@@ -386,6 +395,11 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
}
memset(first_pass_failed, OPJ_TRUE, l_image->numcomps * sizeof(OPJ_BOOL));
if (l_current_pi->poc.prg == OPJ_PROG_UNKNOWN) {
/* TODO ADE : add an error */
opj_pi_destroy(l_pi, l_nb_pocs);
return OPJ_FALSE;
}
while (opj_pi_next(l_current_pi)) {
JAS_FPRINTF( stderr, "packet offset=00000166 prg=%d cmptno=%02d rlvlno=%02d prcno=%03d lyrno=%02d\n\n",
l_current_pi->poc.prg1, l_current_pi->compno, l_current_pi->resno, l_current_pi->precno, l_current_pi->layno );
@@ -477,11 +491,10 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp)
{
/* create the t2 structure */
opj_t2_t *l_t2 = (opj_t2_t*)opj_malloc(sizeof(opj_t2_t));
opj_t2_t *l_t2 = (opj_t2_t*)opj_calloc(1,sizeof(opj_t2_t));
if (!l_t2) {
return NULL;
}
memset(l_t2,0,sizeof(opj_t2_t));
l_t2->image = p_image;
l_t2->cp = p_cp;
@@ -599,6 +612,10 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
}
bio = opj_bio_create();
if (!bio) {
/* FIXME event manager error callback */
return OPJ_FALSE;
}
opj_bio_init_enc(bio, c, length);
opj_bio_write(bio, 1, 1); /* Empty header bit */
@@ -863,11 +880,10 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
if (p_tcp->csty & J2K_CP_CSTY_SOP) {
if (p_max_length < 6) {
/* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNING, "Not enough space for expected SOP marker\n"); */
printf("Not enough space for expected SOP marker\n");
fprintf(stderr, "Not enough space for expected SOP marker\n");
} else if ((*l_current_data) != 0xff || (*(l_current_data + 1) != 0x91)) {
/* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNING, "Expected SOP marker\n"); */
printf("Expected SOP marker\n");
fprintf(stderr, "Error : expected SOP marker\n");
fprintf(stderr, "Warning: expected SOP marker\n");
} else {
l_current_data += 6;
}
@@ -917,7 +933,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
/* EPH markers */
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
if (p_max_length < 2) {
if ((*l_modified_length_ptr - (OPJ_UINT32)(l_header_data - *l_header_data_start)) < 2U) {
fprintf(stderr, "Not enough space for expected EPH marker\n");
} else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
fprintf(stderr, "Error : expected EPH marker\n");
@@ -1045,7 +1061,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
/* EPH markers */
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
if (p_max_length < 2) {
if ((*l_modified_length_ptr - (OPJ_UINT32)(l_header_data - *l_header_data_start)) < 2U) {
fprintf(stderr, "Not enough space for expected EPH marker\n");
} else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
/* TODO opj_event_msg(t2->cinfo->event_mgr, EVT_ERROR, "Expected EPH marker\n"); */
@@ -1129,7 +1145,8 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
}
do {
if (l_current_data + l_seg->newlen > p_src_data + p_max_length) {
/* Check possible overflow (on l_current_data only, assumes input args already checked) then size */
if ((((OPJ_SIZE_T)l_current_data + (OPJ_SIZE_T)l_seg->newlen) < (OPJ_SIZE_T)l_current_data) || (l_current_data + l_seg->newlen > p_src_data + p_max_length)) {
fprintf(stderr, "read: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
return OPJ_FALSE;
@@ -1154,11 +1171,18 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
};
#endif /* USE_JPWL */
/* Check possible overflow on size */
if ((l_cblk->data_current_size + l_seg->newlen) < l_cblk->data_current_size) {
fprintf(stderr, "read: segment too long (%d) with current size (%d > %d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, l_cblk->data_current_size, 0xFFFFFFFF - l_seg->newlen, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
return OPJ_FALSE;
}
/* Check if the cblk->data have allocated enough memory */
if ((l_cblk->data_current_size + l_seg->newlen) > l_cblk->data_max_size) {
OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_realloc(l_cblk->data, l_cblk->data_current_size + l_seg->newlen);
if(! new_cblk_data) {
opj_free(l_cblk->data);
l_cblk->data = NULL;
l_cblk->data_max_size = 0;
/* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to realloc code block cata!\n"); */
return OPJ_FALSE;
@@ -1197,6 +1221,7 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
*(p_data_read) = (OPJ_UINT32)(l_current_data - p_src_data);
return OPJ_TRUE;
}
@@ -1254,7 +1279,8 @@ OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
}
do {
if (* p_data_read + l_seg->newlen > p_max_length) {
/* Check possible overflow then size */
if (((*p_data_read + l_seg->newlen) < (*p_data_read)) || ((*p_data_read + l_seg->newlen) > p_max_length)) {
fprintf(stderr, "skip: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
return OPJ_FALSE;

View File

@@ -175,20 +175,18 @@ opj_tcd_t* opj_tcd_create(OPJ_BOOL p_is_decoder)
opj_tcd_t *l_tcd = 00;
/* create the tcd structure */
l_tcd = (opj_tcd_t*) opj_malloc(sizeof(opj_tcd_t));
l_tcd = (opj_tcd_t*) opj_calloc(1,sizeof(opj_tcd_t));
if (!l_tcd) {
return 00;
}
memset(l_tcd,0,sizeof(opj_tcd_t));
l_tcd->m_is_decoder = p_is_decoder ? 1 : 0;
l_tcd->tcd_image = (opj_tcd_image_t*)opj_malloc(sizeof(opj_tcd_image_t));
l_tcd->tcd_image = (opj_tcd_image_t*)opj_calloc(1,sizeof(opj_tcd_image_t));
if (!l_tcd->tcd_image) {
opj_free(l_tcd);
return 00;
}
memset(l_tcd->tcd_image,0,sizeof(opj_tcd_image_t));
return l_tcd;
}
@@ -467,6 +465,10 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
tile_info->numpix = tcd_tile->numpix;
tile_info->distotile = tcd_tile->distotile;
tile_info->thresh = (OPJ_FLOAT64 *) opj_malloc(tcd_tcp->numlayers * sizeof(OPJ_FLOAT64));
if (!tile_info->thresh) {
/* FIXME event manager error callback */
return OPJ_FALSE;
}
}
for (layno = 0; layno < tcd_tcp->numlayers; layno++) {
@@ -575,23 +577,18 @@ OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
opj_image_t * p_image,
opj_cp_t * p_cp )
{
OPJ_UINT32 l_tile_comp_size;
p_tcd->image = p_image;
p_tcd->cp = p_cp;
p_tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_malloc(sizeof(opj_tcd_tile_t));
p_tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_calloc(1,sizeof(opj_tcd_tile_t));
if (! p_tcd->tcd_image->tiles) {
return OPJ_FALSE;
}
memset(p_tcd->tcd_image->tiles,0, sizeof(opj_tcd_tile_t));
l_tile_comp_size = p_image->numcomps * (OPJ_UINT32)sizeof(opj_tcd_tilecomp_t);
p_tcd->tcd_image->tiles->comps = (opj_tcd_tilecomp_t *) opj_malloc(l_tile_comp_size);
p_tcd->tcd_image->tiles->comps = (opj_tcd_tilecomp_t *) opj_calloc(p_image->numcomps,sizeof(opj_tcd_tilecomp_t));
if (! p_tcd->tcd_image->tiles->comps ) {
return OPJ_FALSE;
}
memset( p_tcd->tcd_image->tiles->comps , 0 , l_tile_comp_size);
p_tcd->tcd_image->tiles->numcomps = p_image->numcomps;
p_tcd->tp_pos = p_cp->m_specific_param.m_enc.m_tp_pos;
@@ -679,7 +676,7 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \
/*tile->numcomps = image->numcomps; */ \
for(compno = 0; compno < l_tile->numcomps; ++compno) { \
/*fprintf(stderr, "compno = %d/%d\n", compno, l_tile->numcomps);*/ \
\
l_image_comp->resno_decoded = 0; \
/* border of each l_tile component (global) */ \
l_tilec->x0 = opj_int_ceildiv(l_tile->x0, (OPJ_INT32)l_image_comp->dx); \
l_tilec->y0 = opj_int_ceildiv(l_tile->y0, (OPJ_INT32)l_image_comp->dy); \
@@ -973,15 +970,14 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \
OPJ_INT32 cblkxend = cblkxstart + (1 << cblkwidthexpn); \
OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn); \
\
if (! FUNCTION_ELEMENT(l_code_block)) { \
return OPJ_FALSE; \
} \
/* code-block size (global) */ \
l_code_block->x0 = opj_int_max(cblkxstart, l_current_precinct->x0); \
l_code_block->y0 = opj_int_max(cblkystart, l_current_precinct->y0); \
l_code_block->x1 = opj_int_min(cblkxend, l_current_precinct->x1); \
l_code_block->y1 = opj_int_min(cblkyend, l_current_precinct->y1); \
\
if (! FUNCTION_ELEMENT(l_code_block)) { \
return OPJ_FALSE; \
} \
++l_code_block; \
} \
++l_current_precinct; \
@@ -1021,20 +1017,17 @@ OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_block)
p_code_block->data+=1;
/* no memset since data */
p_code_block->layers = (opj_tcd_layer_t*) opj_malloc(100 * sizeof(opj_tcd_layer_t));
p_code_block->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t));
if (! p_code_block->layers) {
return OPJ_FALSE;
}
p_code_block->passes = (opj_tcd_pass_t*) opj_malloc(100 * sizeof(opj_tcd_pass_t));
p_code_block->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t));
if (! p_code_block->passes) {
return OPJ_FALSE;
}
}
memset(p_code_block->layers,0,100 * sizeof(opj_tcd_layer_t));
memset(p_code_block->passes,0,100 * sizeof(opj_tcd_pass_t));
return OPJ_TRUE;
}
@@ -1043,8 +1036,6 @@ OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_block)
*/
OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_block)
{
OPJ_UINT32 l_seg_size;
if (! p_code_block->data) {
p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE);
@@ -1054,19 +1045,27 @@ OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_block)
p_code_block->data_max_size = OPJ_J2K_DEFAULT_CBLK_DATA_SIZE;
/*fprintf(stderr, "Allocate 8192 elements of code_block->data\n");*/
l_seg_size = OPJ_J2K_DEFAULT_NB_SEGS * sizeof(opj_tcd_seg_t);
p_code_block->segs = (opj_tcd_seg_t *) opj_malloc(l_seg_size);
p_code_block->segs = (opj_tcd_seg_t *) opj_calloc(OPJ_J2K_DEFAULT_NB_SEGS,sizeof(opj_tcd_seg_t));
if (! p_code_block->segs) {
return OPJ_FALSE;
}
memset(p_code_block->segs,0,l_seg_size);
/*fprintf(stderr, "Allocate %d elements of code_block->data\n", OPJ_J2K_DEFAULT_NB_SEGS * sizeof(opj_tcd_seg_t));*/
p_code_block->m_current_max_segs = OPJ_J2K_DEFAULT_NB_SEGS;
/*fprintf(stderr, "m_current_max_segs of code_block->data = %d\n", p_code_block->m_current_max_segs);*/
}
/* TODO */
/*p_code_block->numsegs = 0; */
} else {
/* sanitize */
OPJ_BYTE* l_data = p_code_block->data;
OPJ_UINT32 l_data_max_size = p_code_block->data_max_size;
opj_tcd_seg_t * l_segs = p_code_block->segs;
OPJ_UINT32 l_current_max_segs = p_code_block->m_current_max_segs;
memset(p_code_block, 0, sizeof(opj_tcd_cblk_dec_t));
p_code_block->data = l_data;
p_code_block->data_max_size = l_data_max_size;
p_code_block->segs = l_segs;
p_code_block->m_current_max_segs = l_current_max_segs;
}
return OPJ_TRUE;
}
@@ -1135,6 +1134,10 @@ OPJ_BOOL opj_tcd_encode_tile( opj_tcd_t *p_tcd,
p_cstr_info->tile[p_tile_no].pdy[i] = (int)l_tccp->prch[i];
}
p_cstr_info->tile[p_tile_no].packet = (opj_packet_info_t*) opj_calloc((size_t)p_cstr_info->numcomps * (size_t)p_cstr_info->numlayers * l_num_packs, sizeof(opj_packet_info_t));
if (!p_cstr_info->tile[p_tile_no].packet) {
/* FIXME event manager error callback */
return OPJ_FALSE;
}
}
/* << INDEX */

View File

@@ -57,12 +57,11 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
OPJ_UINT32 numlvls;
OPJ_UINT32 n;
tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t));
tree = (opj_tgt_tree_t *) opj_calloc(1,sizeof(opj_tgt_tree_t));
if(!tree) {
fprintf(stderr, "ERROR in tgt_create while allocating tree\n");
return 00;
}
memset(tree,0,sizeof(opj_tgt_tree_t));
tree->numleafsh = numleafsh;
tree->numleafsv = numleafsv;
@@ -92,7 +91,6 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
opj_free(tree);
return 00;
}
memset(tree->nodes,0,tree->numnodes * sizeof(opj_tgt_node_t));
tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);
node = tree->nodes;

View File

@@ -57,6 +57,11 @@ set(BLACKLIST_JPEG2000
gdal_fuzzer_unchecked_numresolutions.jp2
mem-b2ace68c-1381.jp2
1851.pdf.SIGSEGV.ce9.948.jp2
1888.pdf.asan.35.988.jp2
issue362-2863.jp2 #kdu_jp2info ok
issue362-2866.jp2
issue362-2894.jp2
issue400.jp2 #kdu_jp2info ok
)
file(GLOB_RECURSE OPJ_DATA_NR_LIST

View File

@@ -41,22 +41,12 @@ endif()
file(READ ${REFFILE} variable)
foreach(pgxfullpath ${globfiles})
file(MD5 ${pgxfullpath} output)
get_filename_component(pgxfile ${pgxfullpath} NAME)
execute_process(
COMMAND ${CMAKE_COMMAND} -E md5sum ${pgxfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Temporary
RESULT_VARIABLE res
OUTPUT_VARIABLE output
ERROR_VARIABLE error_output
OUTPUT_STRIP_TRAILING_WHITESPACE # important
)
# Pass the output back to ctest
if(res)
message(SEND_ERROR "md5 could not be computed, it failed with value ${res}. Output was: ${error_output}")
endif()
string(REGEX MATCH "[0-9a-f]+ ${pgxfile}" output_var "${variable}")
set(output "${output} ${pgxfile}")
if("${output_var}" STREQUAL "${output}")
message(STATUS "equal: [${output_var}] vs [${output}]")

View File

@@ -174,6 +174,26 @@ opj_decompress -i @INPUT_NR_PATH@/issue226.j2k -o @TEMP_PATH@/
#!opj_decompress -i @INPUT_NR_PATH@/3459.pdf.asan.6c.2734.0.jp2 -o @TEMP_PATH@/3459.pdf.asan.6c.2734.0.jp2.pgx
#!opj_decompress -i @INPUT_NR_PATH@/3459.pdf.asan.6c.2734.1.jp2 -o @TEMP_PATH@/3459.pdf.asan.6c.2734.1.jp2.pgx
#!opj_decompress -i @INPUT_NR_PATH@/3459.pdf.asan.6c.2734.2.jp2 -o @TEMP_PATH@/3459.pdf.asan.6c.2734.2.jp2.pgx
# issue 362 (from pdfium fuzz engine)
# Invalid PPM Marker
!opj_decompress -i @INPUT_NR_PATH@/issue362-2863.jp2 -o @TEMP_PATH@/issue362-2863.jp2.pgx
# Invalid ftyp box size
!opj_decompress -i @INPUT_NR_PATH@/issue362-2866.jp2 -o @TEMP_PATH@/issue362-2866.jp2.pgx
!opj_decompress -i @INPUT_NR_PATH@/issue362-2894.jp2 -o @TEMP_PATH@/issue362-2894.jp2.pgx
# issue 363 (from pdfium fuzz engine)
# Invalid Tile part length
!opj_decompress -i @INPUT_NR_PATH@/issue363-4723.jp2 -o @TEMP_PATH@/issue363-4723.jp2.pgx
# Invalid Marker length
!opj_decompress -i @INPUT_NR_PATH@/issue363-4740.jp2 -o @TEMP_PATH@/issue363-4740.jp2.pgx
!opj_decompress -i @INPUT_NR_PATH@/issue363-4792.jp2 -o @TEMP_PATH@/issue363-4792.jp2.pgx
# issue 390 (from pdfium fuzz engine) Invalid segment size
!opj_decompress -i @INPUT_NR_PATH@/issue390.jp2 -o @TEMP_PATH@/issue390.jp2.pgx
# issue 391 (from pdfium fuzz engine) Invalid segment size
!opj_decompress -i @INPUT_NR_PATH@/issue391.jp2 -o @TEMP_PATH@/issue391.jp2.pgx
# issue 400 (from pdfium fuzz engine) Unknown Scod value in COD marker
!opj_decompress -i @INPUT_NR_PATH@/issue400.jp2 -o @TEMP_PATH@/issue400.jp2.pgx
# issue 413 (from pdfium fuzz engine) Unknown progression order in COD marker
!opj_decompress -i @INPUT_NR_PATH@/issue413.jp2 -o @TEMP_PATH@/issue413.jp2.pgx
# decode with specific area
# prec=12; nb_c=1

View File

@@ -37,6 +37,11 @@
* only work on linux since I need memmem function
*/
/*
* Add support for other signatures:
*
* obj<</Subtype/Image/Length 110494/Filter/JPXDecode/BitsPerComponent 8/ColorSpace/DeviceRGB/Width 712/Height 1052>>stream
*/
#define _GNU_SOURCE
#include <string.h>
#include <stdio.h>
@@ -98,7 +103,17 @@ int main(int argc, char *argv[])
assert( r );
/*fprintf( stderr, "DEBUG: %s", r );*/
s = sscanf(r, "JPXDecode]/Length %d/Width %*d/BitsPerComponent %*d/Height %*d", &len);
assert( s == 1 );
if( s == 0 )
{ // try again harder
const int ret = fseek(f, offets[i] - 40, SEEK_SET); // 40 is magic number
assert( ret == 0 );
r = fgets(buffer, sizeof(buffer), f);
assert( r );
const char needle2[] = "/Length";
char * s2 = strstr(buffer, needle2);
s = sscanf(s2, "/Length %d/", &len);
}
if( s == 1 )
{
FILE *jp2;
int j;