diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-04-16 23:34:42 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-04-16 23:34:42 +0200 |
| commit | e46e6c6054e4294c35d0f5e17de251b2fbb94cdc (patch) | |
| tree | d0e50ab76520dcf21a80b4800b3f05271b53dea6 /src/verify_j2k.cc | |
| parent | eda64d142769ca4e81578fc1dc59e265eac28ac7 (diff) | |
Check for tile parts being too big in the verifier (DoM #2450).
Diffstat (limited to 'src/verify_j2k.cc')
| -rw-r--r-- | src/verify_j2k.cc | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/verify_j2k.cc b/src/verify_j2k.cc index 86ffb5b4..b9158849 100644 --- a/src/verify_j2k.cc +++ b/src/verify_j2k.cc @@ -65,8 +65,11 @@ public: void -dcp::verify_j2k (shared_ptr<const Data> j2k, vector<VerificationNote>& notes) +dcp::verify_j2k(shared_ptr<const Data> j2k, int frame_index, int frame_rate, vector<VerificationNote>& notes) { + /* See ITU-T T800 (visible on https://github.com/Ymagis/ClairMeta/issues/130) */ + unsigned int const max_tile_part_size = std::floor(200e6 / (8 * frame_rate)); + try { auto ptr = j2k->data(); auto end = ptr + j2k->size(); @@ -202,8 +205,8 @@ dcp::verify_j2k (shared_ptr<const Data> j2k, vector<VerificationNote>& notes) } else if (*marker_name == "SOT") { require_16(10, "invalid SOT size %1"); get_16(); // tile index - get_32(); // tile part length - get_8(); // tile part index + auto const tile_part_length = get_32(); + auto const tile_part_index = get_8(); auto tile_parts = get_8(); if (!fourk && tile_parts != 3) { notes.push_back ({ VerificationNote::Type::BV21_ERROR, VerificationNote::Code::INVALID_JPEG2000_TILE_PARTS_FOR_2K, raw_convert<string>(tile_parts) }); @@ -211,6 +214,13 @@ dcp::verify_j2k (shared_ptr<const Data> j2k, vector<VerificationNote>& notes) if (fourk && tile_parts != 6) { notes.push_back ({ VerificationNote::Type::BV21_ERROR, VerificationNote::Code::INVALID_JPEG2000_TILE_PARTS_FOR_4K, raw_convert<string>(tile_parts) }); } + if (tile_part_length > max_tile_part_size) { + VerificationNote note{VerificationNote::Type::ERROR, VerificationNote::Code::INVALID_JPEG2000_TILE_PART_SIZE}; + note.set_frame(frame_index); + note.set_component(tile_part_index); + note.set_size(tile_part_length); + notes.push_back(note); + } main_header_finished = true; } else if (*marker_name == "SOD") { while (ptr < (end - 1) && (ptr[0] != 0xff || ptr[1] < 0x90)) { |
