Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/apps/common/ojph_img_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ namespace ojph {
mem_fixed_allocator *alloc_p;
void *temp_buf;
ui32 width, height, num_comps, max_val, max_val_num_bits;
ui32 bytes_per_sample, num_ele_per_line;
ui32 temp_buf_byte_size;
ui32 bytes_per_sample;
size_t num_ele_per_line;
size_t temp_buf_byte_size;

ui32 cur_line;
si64 start_of_data;
Expand Down Expand Up @@ -728,7 +729,7 @@ namespace ojph {
ui32 bit_depth;
ui32 *comp_width;
ui8 *buffer;
ui32 buffer_size;
size_t buffer_size;
};

////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -767,7 +768,7 @@ namespace ojph {
si64 lower_val, upper_val;
ui32 width;
ui8* buffer;
ui32 buffer_size;
size_t buffer_size;
};

////////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 6 additions & 6 deletions src/apps/others/ojph_img_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,19 @@ namespace ojph {
close();
OJPH_ERROR(0x03000006, "error in file format for file %s", filename);
}
num_ele_per_line = num_comps * width;
num_ele_per_line = num_comps * (size_t)width;
bytes_per_sample = max_val > 255 ? 2 : 1;
max_val_num_bits = 32u - count_leading_zeros(max_val);
bit_depth[2] = bit_depth[1] = bit_depth [0] = max_val_num_bits;
fgetc(fh);
start_of_data = ojph_ftell(fh);

// allocate linebuffer to hold a line of image data
if (temp_buf_byte_size < num_comps * width * bytes_per_sample)
if (temp_buf_byte_size < num_comps * (size_t)width * bytes_per_sample)
{
if (alloc_p == NULL)
{
temp_buf_byte_size = num_comps * width * bytes_per_sample;
temp_buf_byte_size = num_comps * (size_t)width * bytes_per_sample;
void* t = temp_buf;
if (temp_buf)
temp_buf = realloc(temp_buf, temp_buf_byte_size);
Expand All @@ -323,7 +323,7 @@ namespace ojph {
else
{
assert(temp_buf_byte_size == 0); //cannot reallocate the buffer
temp_buf_byte_size = num_comps * width * bytes_per_sample;
temp_buf_byte_size = num_comps * (size_t)width * bytes_per_sample;
alloc_p->pre_alloc_data<ui8>(temp_buf_byte_size, 0);
}
}
Expand Down Expand Up @@ -1477,7 +1477,7 @@ namespace ojph {
tw = ojph_max(tw, this->comp_width[i]);
}
this->width = tw;
buffer_size = tw * (bit_depth > 8 ? 2 : 1);
buffer_size = (size_t)tw * (bit_depth > 8 ? 2 : 1);
buffer = (ui8*)malloc(buffer_size);
}

Expand Down Expand Up @@ -1678,7 +1678,7 @@ namespace ojph {
}

bytes_per_sample = (bit_depth + 7) >> 3;
buffer_size = width * bytes_per_sample;
buffer_size = (size_t)width * bytes_per_sample;
buffer = (ui8*)malloc(buffer_size);
}

Expand Down