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
2 changes: 1 addition & 1 deletion lib/jpegli/encode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ void jpegli_add_quant_table(j_compress_ptr cinfo, int which_tbl,
const unsigned int* basic_table, int scale_factor,
boolean force_baseline) {
CheckState(cinfo, jpegli::kEncStart);
if (which_tbl < 0 || which_tbl > NUM_QUANT_TBLS) {
if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS) {
JPEGLI_ERROR("Invalid quant table index %d", which_tbl);
}
if (cinfo->quant_tbl_ptrs[which_tbl] == nullptr) {
Expand Down
27 changes: 27 additions & 0 deletions lib/jpegli/error_handling_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,33 @@ TEST(EncoderErrorHandlingTest, InvalidQuantTableIndex) {
if (buffer) free(buffer);
}

TEST(EncoderErrorHandlingTest, AddQuantTableInvalidIndex) {
uint8_t* buffer = nullptr;
unsigned long buffer_size = 0; // NOLINT
jpeg_compress_struct cinfo;
const auto try_catch_block = [&]() -> bool {
ERROR_HANDLER_SETUP(jpegli);
jpegli_create_compress(&cinfo);
jpegli_mem_dest(&cinfo, &buffer, &buffer_size);
cinfo.image_width = 1;
cinfo.image_height = 1;
cinfo.input_components = 1;
jpegli_set_defaults(&cinfo);
unsigned int basic_table[DCTSIZE2];
for (unsigned int& v : basic_table) v = 1;
jpegli_add_quant_table(&cinfo, NUM_QUANT_TBLS, basic_table, 100, TRUE);
jpegli_start_compress(&cinfo, TRUE);
JSAMPLE image[1] = {0};
JSAMPROW row[] = {image};
jpegli_write_scanlines(&cinfo, row, 1);
jpegli_finish_compress(&cinfo);
return true;
};
EXPECT_FALSE(try_catch_block());
jpegli_destroy_compress(&cinfo);
if (buffer) free(buffer);
}

TEST(EncoderErrorHandlingTest, NumberOfComponentsMismatch1) {
uint8_t* buffer = nullptr;
unsigned long buffer_size = 0; // NOLINT
Expand Down