Skip to content

Commit

Permalink
Push version to 0.7.3. A few bug fixes, and some code hardening -- Th…
Browse files Browse the repository at this point in the history
…is is back-ported from the development branch, because there is need for it.
  • Loading branch information
aous72 committed Mar 12, 2021
1 parent d0d4b1d commit d92d70c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /D \"_CRT_SECURE_NO_WARNINGS\"")
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-Wall -Wextra -Wconversion -Wunused-parameter")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-fexceptions -Wall -Wextra -Wconversion -Wunused-parameter")
endif()

if (OJPH_DISABLE_INTEL_SIMD)
Expand Down
48 changes: 34 additions & 14 deletions src/core/codestream/ojph_codestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1869,9 +1869,9 @@ namespace ojph {
catch (const char *error)
{
if (resilient)
OJPH_INFO(0x00030092, "%s\n", error)
OJPH_INFO(0x00030092, "%s", error)
else
OJPH_ERROR(0x00030092, "%s\n", error)
OJPH_ERROR(0x00030092, "%s", error)
}
file->seek(tile_end_location, infile_base::OJPH_SEEK_SET);
}
Expand Down Expand Up @@ -3250,16 +3250,23 @@ namespace ojph {
mem_elastic_allocator *elastic)
{
assert(bbp->avail_bits == 0 && bbp->unstuff == false);
ui32 bytes = ojph_min(num_bytes, bbp->bytes_left);
elastic->get_buffer(bytes + coded_cb_header::prefix_buf_size
if (num_bytes > bbp->bytes_left)
{
bbp->bytes_left = 0;
return false;
}
elastic->get_buffer(num_bytes + coded_cb_header::prefix_buf_size
+ coded_cb_header::suffix_buf_size, cur_coded_list);
ui32 bytes_read = (ui32)bbp->file->read(
cur_coded_list->buf + coded_cb_header::prefix_buf_size, bytes);
if (num_bytes > bytes_read)
memset(cur_coded_list->buf + coded_cb_header::prefix_buf_size + bytes,
0, num_bytes - bytes_read);
cur_coded_list->buf + coded_cb_header::prefix_buf_size, num_bytes);
if (bytes_read < num_bytes)
{
bbp->bytes_left = 0;
return false;
}
assert(num_bytes == bytes_read);
bbp->bytes_left -= bytes_read;
return bytes_read == bytes;
return true;
}

//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3527,13 +3534,17 @@ namespace ojph {
{
//no need to decode a broken codeblock
cp->pass_length[0] = cp->pass_length[1] = 0;
cp->num_passes = 0;
data_left = 0;
}
}
}
}
else
{
cp->pass_length[0] = cp->pass_length[1] = 0;
cp->num_passes = 0;
}
}
}
}
Expand Down Expand Up @@ -3905,6 +3916,7 @@ namespace ojph {
this->cur_line = 0;
this->K_max = K_max;
this->max_val = 0;
this->resilient = codestream->is_resilient();
this->coded_cb = coded_cb;
}

Expand Down Expand Up @@ -3954,11 +3966,19 @@ namespace ojph {
{
if (coded_cb->pass_length[0] > 0 && coded_cb->num_passes > 0)
{
ojph_decode_codeblock(
coded_cb->next_coded->buf + coded_cb_header::prefix_buf_size,
buf, coded_cb->missing_msbs, coded_cb->num_passes,
coded_cb->pass_length[0], coded_cb->pass_length[1],
cb_size.w, cb_size.h, cb_size.w);
bool result =
ojph_decode_codeblock(
coded_cb->next_coded->buf + coded_cb_header::prefix_buf_size,
buf, coded_cb->missing_msbs, coded_cb->num_passes,
coded_cb->pass_length[0], coded_cb->pass_length[1],
cb_size.w, cb_size.h, cb_size.w);
if (result == false)
{
if (resilient == true)
memset(buf, 0, cb_size.area() * sizeof(si32));
else
OJPH_ERROR(0x000300A1, "Error decoding a codeblock\n");
}
}
else
memset(buf, 0, cb_size.area() * sizeof(si32));
Expand Down
1 change: 1 addition & 0 deletions src/core/codestream/ojph_codestream_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ namespace ojph {
int cur_line;
int K_max;
int max_val;
bool resilient;
coded_cb_header* coded_cb;
};

Expand Down
47 changes: 35 additions & 12 deletions src/core/coding/ojph_block_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,13 @@ namespace ojph {
//process 4 bytes at a time
if (vlcp->bits > 32)
return;
ui32 val;
val = *(ui32*)vlcp->data;
vlcp->data -= 4;
ui32 val = 0;
if (vlcp->size > 0) // if there are bytes left in the VLC segment
{
val = *(ui32*)vlcp->data; // then read 32 bits
vlcp->data -= 4; // move data pointer back by 4
vlcp->size -= 4; // reduce available byte by 4
}

//accumulate in int and then push into the registers
ui32 tmp = val >> 24;
Expand All @@ -242,14 +246,6 @@ namespace ojph {
vlcp->tmp |= (ui64)tmp << vlcp->bits;
vlcp->bits += bits;
vlcp->unstuff = unstuff;

vlcp->size -= 4;
//because we read ahead of time, we might in fact exceed vlc size,
// but data should not be used if the codeblock is properly generated
//The mel code can in fact occupy zero length, if it has a small number
// of bits and these bits overlap with the VLC code
if (vlcp->size < -8) //8 is based on the fact that we may read 64 bits
OJPH_ERROR(0x00010001, "Error in reading VLC data");
}

/////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -701,7 +697,28 @@ namespace ojph {
//pointers to arrays to be used interchangeably
int sip_shift = 0; //decides where data go

int p = 30 - missing_msbs; // Bit-plane index for cleanup pass
if (num_passes > 1 && lengths2 == 0)
{
OJPH_WARN(0x00010001, "A malformed codeblock that has more than "
"one coding pass, but zero length for "
"2nd and potential 3rd pass.\n");
num_passes = 1;
}
if (num_passes > 3)
{
OJPH_ERROR(0x00010002, "We do not support more than 3 coding passes; "
"This codeblocks has %d passes.\n",
num_passes);
return false;
}

if (missing_msbs > 29) // p < 1
return false; // 32 bits are not enough to decode this
else if (missing_msbs == 29) // if p is 1, then num_passes must be 1
num_passes = 1;
ui32 p = 30 - missing_msbs; // The least significant bitplane for CUP
// There is a way to handle the case of p == 0, but a different path
// is required

// read scup and fix the bytes there
int lcup, scup;
Expand Down Expand Up @@ -797,6 +814,9 @@ namespace ojph {
run = mel_get_run(&mel);
}
int consumed_bits = decode_init_uvlc(vlc_val, uvlc_mode, U_p);
if (U_p[0] > missing_msbs + 1 || U_p[1] > missing_msbs + 1)
return false;

vlc_val = rev_advance(&vlc, consumed_bits);

//decode magsgn and update line_state
Expand Down Expand Up @@ -1040,6 +1060,9 @@ namespace ojph {
U_p[1] += E > 0 ? E : 0;
}

if (U_p[0] > missing_msbs + 1 || U_p[1] > missing_msbs + 1)
return false;

ls0 = lsp[2]; //for next double quad
lsp[1] = lsp[2] = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/core/common/ojph_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@

#define OPENJPH_VERSION_MAJOR 0
#define OPENJPH_VERSION_MINOR 7
#define OPENJPH_VERSION_PATCH 2
#define OPENJPH_VERSION_PATCH 3

0 comments on commit d92d70c

Please sign in to comment.