summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/openjp2/dwt.c4
-rw-r--r--src/lib/openjp2/j2k.c4
-rw-r--r--src/lib/openjp2/jp2.c40
-rw-r--r--src/lib/openjp2/opj_config_private.h.cmake.in10
-rw-r--r--src/lib/openjp2/opj_malloc.c30
-rw-r--r--src/lib/openjp2/pi.c16
-rw-r--r--src/lib/openjp3d/tcd.c4
-rw-r--r--src/lib/openmj2/mj2.h2
-rw-r--r--src/lib/openmj2/tcd.c2
9 files changed, 61 insertions, 51 deletions
diff --git a/src/lib/openjp2/dwt.c b/src/lib/openjp2/dwt.c
index d63c120e..a4ff01ba 100644
--- a/src/lib/openjp2/dwt.c
+++ b/src/lib/openjp2/dwt.c
@@ -409,7 +409,9 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void
l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * (OPJ_UINT32)sizeof(OPJ_INT32);
bj = (OPJ_INT32*)opj_malloc((size_t)l_data_size);
- if (! bj) {
+ /* l_data_size is equal to 0 when numresolutions == 1 but bj is not used */
+ /* in that case, so do not error out */
+ if (l_data_size != 0 && ! bj) {
return OPJ_FALSE;
}
i = l;
diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c
index e8522277..f0e565ea 100644
--- a/src/lib/openjp2/j2k.c
+++ b/src/lib/openjp2/j2k.c
@@ -9886,7 +9886,7 @@ static OPJ_BOOL opj_j2k_decode_one_tile ( opj_j2k_t *p_j2k,
if(l_current_tile_no == l_tile_no_to_dec)
{
- /* move into the codestream to the the first SOT (FIXME or not move?)*/
+ /* move into the codestream to the first SOT (FIXME or not move?)*/
if (!(opj_stream_read_seek(p_stream, p_j2k->cstr_index->main_head_end + 2, p_manager) ) ) {
opj_event_msg(p_manager, EVT_ERROR, "Problem with seek function\n");
opj_free(l_current_data);
@@ -10952,7 +10952,7 @@ OPJ_BOOL opj_j2k_write_tile (opj_j2k_t * p_j2k,
}
}
- /* now copy data into the the tile component */
+ /* now copy data into the tile component */
if (! opj_tcd_copy_tile_data(p_j2k->m_tcd,p_data,p_data_size)) {
opj_event_msg(p_manager, EVT_ERROR, "Size mismatch between tile data and sent data." );
return OPJ_FALSE;
diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c
index c14e9a06..6c6f6e83 100644
--- a/src/lib/openjp2/jp2.c
+++ b/src/lib/openjp2/jp2.c
@@ -94,7 +94,7 @@ static OPJ_BYTE * opj_jp2_write_bpcc( opj_jp2_t *jp2,
* @param p_bpc_header_size the size of the bpc header
* @param p_manager the user event manager.
*
- * @return true if the bpc header is valid, fale else.
+ * @return true if the bpc header is valid, false else.
*/
static OPJ_BOOL opj_jp2_read_bpcc( opj_jp2_t *jp2,
OPJ_BYTE * p_bpc_header_data,
@@ -311,7 +311,7 @@ static OPJ_BOOL opj_jp2_read_cmap( opj_jp2_t * jp2,
* @param p_colr_header_size the size of the color header
* @param p_manager the user event manager.
*
- * @return true if the bpc header is valid, fale else.
+ * @return true if the bpc header is valid, false else.
*/
static OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
OPJ_BYTE * p_colr_header_data,
@@ -482,12 +482,16 @@ static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box,
opj_read_bytes(l_data_header+4,&(box->type), 4);
if(box->length == 0)/* last box */
- {
+ {
const OPJ_OFF_T bleft = opj_stream_get_number_byte_left(cio);
- box->length = (OPJ_UINT32)bleft;
- assert( (OPJ_OFF_T)box->length == bleft );
- return OPJ_TRUE;
+ if (bleft > (OPJ_OFF_T)(0xFFFFFFFFU - 8U)) {
+ opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box sizes higher than 2^32\n");
+ return OPJ_FALSE;
}
+ box->length = (OPJ_UINT32)bleft + 8U;
+ assert( (OPJ_OFF_T)box->length == bleft + 8 );
+ return OPJ_TRUE;
+ }
/* do we have a "special very large box ?" */
/* read then the XLBox */
@@ -2112,7 +2116,7 @@ static OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
if (box.type == JP2_JP2C) {
if (jp2->jp2_state & JP2_STATE_HEADER) {
jp2->jp2_state |= JP2_STATE_CODESTREAM;
- opj_free(l_current_data);
+ opj_free(l_current_data);
return OPJ_TRUE;
}
else {
@@ -2127,7 +2131,7 @@ static 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;
@@ -2184,16 +2188,16 @@ static OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
}
}
else {
- if (!(jp2->jp2_state & JP2_STATE_SIGNATURE)) {
- opj_event_msg(p_manager, EVT_ERROR, "Malformed JP2 file format: first box must be JPEG 2000 signature box\n");
- opj_free(l_current_data);
- return OPJ_FALSE;
- }
- if (!(jp2->jp2_state & JP2_STATE_FILE_TYPE)) {
- opj_event_msg(p_manager, EVT_ERROR, "Malformed JP2 file format: second box must be file type box\n");
- opj_free(l_current_data);
- return OPJ_FALSE;
- }
+ if (!(jp2->jp2_state & JP2_STATE_SIGNATURE)) {
+ opj_event_msg(p_manager, EVT_ERROR, "Malformed JP2 file format: first box must be JPEG 2000 signature box\n");
+ opj_free(l_current_data);
+ return OPJ_FALSE;
+ }
+ if (!(jp2->jp2_state & JP2_STATE_FILE_TYPE)) {
+ opj_event_msg(p_manager, EVT_ERROR, "Malformed JP2 file format: second box must be file type box\n");
+ opj_free(l_current_data);
+ return OPJ_FALSE;
+ }
jp2->jp2_state |= JP2_STATE_UNKNOWN;
if (opj_stream_skip(stream,l_current_data_size,p_manager) != l_current_data_size) {
opj_event_msg(p_manager, EVT_ERROR, "Problem with skipping JPEG2000 box, stream error\n");
diff --git a/src/lib/openjp2/opj_config_private.h.cmake.in b/src/lib/openjp2/opj_config_private.h.cmake.in
index 97c9fdc5..b05822c3 100644
--- a/src/lib/openjp2/opj_config_private.h.cmake.in
+++ b/src/lib/openjp2/opj_config_private.h.cmake.in
@@ -18,15 +18,15 @@
#cmakedefine OPJ_HAVE_FSEEKO @OPJ_HAVE_FSEEKO@
/* find whether or not have <malloc.h> */
-#cmakedefine HAVE_MALLOC_H
+#cmakedefine OPJ_HAVE_MALLOC_H
/* check if function `aligned_alloc` exists */
-#cmakedefine HAVE_ALIGNED_ALLOC
+#cmakedefine OPJ_HAVE_ALIGNED_ALLOC
/* check if function `_aligned_malloc` exists */
-#cmakedefine HAVE__ALIGNED_MALLOC
+#cmakedefine OPJ_HAVE__ALIGNED_MALLOC
/* check if function `memalign` exists */
-#cmakedefine HAVE_MEMALIGN
+#cmakedefine OPJ_HAVE_MEMALIGN
/* check if function `posix_memalign` exists */
-#cmakedefine HAVE_POSIX_MEMALIGN
+#cmakedefine OPJ_HAVE_POSIX_MEMALIGN
/* Byte order. */
/* All compilers that support Mac OS X define either __BIG_ENDIAN__ or
diff --git a/src/lib/openjp2/opj_malloc.c b/src/lib/openjp2/opj_malloc.c
index a4aea30f..e04db912 100644
--- a/src/lib/openjp2/opj_malloc.c
+++ b/src/lib/openjp2/opj_malloc.c
@@ -1,6 +1,6 @@
/*
- * The copyright in this software is being made available under the 2-clauses
- * BSD License, included below. This software may be subject to other third
+ * The copyright in this software is being made available under the 2-clauses
+ * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@@ -32,6 +32,10 @@
#define OPJ_SKIP_POISON
#include "opj_includes.h"
+#if defined(OPJ_HAVE_MALLOC_H) && defined(OPJ_HAVE_MEMALIGN)
+# include <malloc.h>
+#endif
+
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
@@ -49,7 +53,7 @@ static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size)
return NULL;
}
-#if defined(HAVE_POSIX_MEMALIGN)
+#if defined(OPJ_HAVE_POSIX_MEMALIGN)
/* aligned_alloc requires c11, restrict to posix_memalign for now. Quote:
* This function was introduced in POSIX 1003.1d. Although this function is
* superseded by aligned_alloc, it is more portable to older POSIX systems
@@ -59,16 +63,16 @@ static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size)
ptr = NULL;
}
/* older linux */
-#elif defined(HAVE_MEMALIGN)
+#elif defined(OPJ_HAVE_MEMALIGN)
ptr = memalign( alignment, size );
/* _MSC_VER */
-#elif defined(HAVE__ALIGNED_MALLOC)
+#elif defined(OPJ_HAVE__ALIGNED_MALLOC)
ptr = _aligned_malloc(size, alignment);
#else
/*
* Generic aligned malloc implementation.
* Uses size_t offset for the integer manipulation of the pointer,
- * as uintptr_t is not available in C89 to do
+ * as uintptr_t is not available in C89 to do
* bitwise operations on the pointer itself.
*/
alignment--;
@@ -78,7 +82,7 @@ static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size)
/* Room for padding and extra pointer stored in front of allocated area */
size_t overhead = alignment + sizeof(void *);
-
+
/* let's be extra careful */
assert(alignment <= (SIZE_MAX - sizeof(void *)));
@@ -114,8 +118,8 @@ static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, size_t ne
}
/* no portable aligned realloc */
-#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_MEMALIGN)
- /* glibc doc states one can mixed aligned malloc with realloc */
+#if defined(OPJ_HAVE_POSIX_MEMALIGN) || defined(OPJ_HAVE_MEMALIGN)
+ /* glibc doc states one can mix aligned malloc with realloc */
r_ptr = realloc( ptr, new_size ); /* fast path */
/* we simply use `size_t` to cast, since we are only interest in binary AND
* operator */
@@ -132,7 +136,7 @@ static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, size_t ne
r_ptr = a_ptr;
}
/* _MSC_VER */
-#elif defined(HAVE__ALIGNED_MALLOC)
+#elif defined(OPJ_HAVE__ALIGNED_MALLOC)
r_ptr = _aligned_realloc( ptr, new_size, alignment );
#else
if (ptr == NULL) {
@@ -151,7 +155,7 @@ static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, size_t ne
if (new_size > SIZE_MAX - overhead) {
return NULL;
}
-
+
oldmem = ((void**) ptr)[-1];
newmem = (OPJ_UINT8*)realloc(oldmem, new_size + overhead);
if (newmem == NULL) {
@@ -210,9 +214,9 @@ void * opj_aligned_realloc(void *ptr, size_t size)
void opj_aligned_free(void* ptr)
{
-#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_MEMALIGN)
+#if defined(OPJ_HAVE_POSIX_MEMALIGN) || defined(OPJ_HAVE_MEMALIGN)
free( ptr );
-#elif defined(HAVE__ALIGNED_MALLOC)
+#elif defined(OPJ_HAVE__ALIGNED_MALLOC)
_aligned_free( ptr );
#else
/* Generic implementation has malloced pointer stored in front of used area */
diff --git a/src/lib/openjp2/pi.c b/src/lib/openjp2/pi.c
index 1697bcbc..bfee10a2 100644
--- a/src/lib/openjp2/pi.c
+++ b/src/lib/openjp2/pi.c
@@ -136,10 +136,10 @@ static void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp,
* @param p_tx1 pointer that will hold the X1 parameter for the tile
* @param p_ty0 pointer that will hold the Y0 parameter for the tile
* @param p_ty1 pointer that will hold the Y1 parameter for the tile
- * @param p_max_prec pointer that will hold the the maximum precision for all the bands of the tile
- * @param p_max_res pointer that will hold the the maximum number of resolutions for all the poc inside the tile.
- * @param p_dx_min pointer that will hold the the minimum dx of all the components of all the resolutions for the tile.
- * @param p_dy_min pointer that will hold the the minimum dy of all the components of all the resolutions for the tile.
+ * @param p_max_prec pointer that will hold the maximum precision for all the bands of the tile
+ * @param p_max_res pointer that will hold the maximum number of resolutions for all the poc inside the tile.
+ * @param p_dx_min pointer that will hold the minimum dx of all the components of all the resolutions for the tile.
+ * @param p_dy_min pointer that will hold the minimum dy of all the components of all the resolutions for the tile.
*/
static void opj_get_encoding_parameters(const opj_image_t *p_image,
const opj_cp_t *p_cp,
@@ -167,10 +167,10 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image,
* @param p_tx1 pointer that will hold the X1 parameter for the tile
* @param p_ty0 pointer that will hold the Y0 parameter for the tile
* @param p_ty1 pointer that will hold the Y1 parameter for the tile
- * @param p_max_prec pointer that will hold the the maximum precision for all the bands of the tile
- * @param p_max_res pointer that will hold the the maximum number of resolutions for all the poc inside the tile.
- * @param p_dx_min pointer that will hold the the minimum dx of all the components of all the resolutions for the tile.
- * @param p_dy_min pointer that will hold the the minimum dy of all the components of all the resolutions for the tile.
+ * @param p_max_prec pointer that will hold the maximum precision for all the bands of the tile
+ * @param p_max_res pointer that will hold the maximum number of resolutions for all the poc inside the tile.
+ * @param p_dx_min pointer that will hold the minimum dx of all the components of all the resolutions for the tile.
+ * @param p_dy_min pointer that will hold the minimum dy of all the components of all the resolutions for the tile.
* @param p_resolutions pointer to an area corresponding to the one described above.
*/
static void opj_get_all_encoding_parameters(const opj_image_t *p_image,
diff --git a/src/lib/openjp3d/tcd.c b/src/lib/openjp3d/tcd.c
index 0c662ce8..1d0d0f52 100644
--- a/src/lib/openjp3d/tcd.c
+++ b/src/lib/openjp3d/tcd.c
@@ -1601,7 +1601,7 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno) {
if (l == -999) {
eof = 1;
- opj_event_msg(tcd->cinfo, EVT_ERROR, "Tcd_decode_tile: incomplete bistream\n");
+ opj_event_msg(tcd->cinfo, EVT_ERROR, "Tcd_decode_tile: incomplete bitstream\n");
}
/*------------------TIER1-----------------*/
@@ -1631,7 +1631,7 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno) {
golomb_destroy(gr);
if (l == -999) {
eof = 1;
- opj_event_msg(tcd->cinfo, EVT_ERROR, "Tcd_decode_tile: incomplete bistream\n");
+ opj_event_msg(tcd->cinfo, EVT_ERROR, "Tcd_decode_tile: incomplete bitstream\n");
}
*/
}
diff --git a/src/lib/openmj2/mj2.h b/src/lib/openmj2/mj2.h
index 611e6350..8761111f 100644
--- a/src/lib/openmj2/mj2.h
+++ b/src/lib/openmj2/mj2.h
@@ -378,7 +378,7 @@ Read the structure of an MJ2 file
*/
OPJ_API int OPJ_CALLCONV mj2_read_struct(FILE *file, opj_mj2_t *mj2);
/**
-Write the the MOOV box to an output buffer stream
+Write the MOOV box to an output buffer stream
@param movie MJ2 movie structure
@param cio Output buffer stream
*/
diff --git a/src/lib/openmj2/tcd.c b/src/lib/openmj2/tcd.c
index 5eb5f4bb..7875737c 100644
--- a/src/lib/openmj2/tcd.c
+++ b/src/lib/openmj2/tcd.c
@@ -1386,7 +1386,7 @@ opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno
if (l == -999) {
eof = 1;
- opj_event_msg(tcd->cinfo, EVT_ERROR, "tcd_decode: incomplete bistream\n");
+ opj_event_msg(tcd->cinfo, EVT_ERROR, "tcd_decode: incomplete bitstream\n");
}
/*------------------TIER1-----------------*/