diff --git a/libheif/plugins/decoder_openh264.cc b/libheif/plugins/decoder_openh264.cc index a3eb6c60ca..163331da9d 100644 --- a/libheif/plugins/decoder_openh264.cc +++ b/libheif/plugins/decoder_openh264.cc @@ -130,6 +130,7 @@ struct heif_error openh264_decode_image(void* decoder_raw, struct heif_image** o std::vector scdata; size_t idx = 0; + auto end = &indata[0]; while (idx < indata.size()) { if (indata.size() - 4 < idx) { return kError_EOF; @@ -162,7 +163,8 @@ struct heif_error openh264_decode_image(void* decoder_raw, struct heif_image** o scdata.push_back(0); scdata.push_back(3); - scdata.insert(scdata.end(), &indata[idx + 2], &indata[idx + i + 2]); + end = (&indata[idx + i + 1])+1; + scdata.insert(scdata.end(), &indata[idx + 2], end); idx += i + 2; size -= (uint32_t)(i + 2); found_start_code_emulation = true; @@ -174,7 +176,8 @@ struct heif_error openh264_decode_image(void* decoder_raw, struct heif_image** o } assert(size > 0); - scdata.insert(scdata.end(), &indata[idx], &indata[idx + size]); + end = (&indata[idx + size - 1])+1; + scdata.insert(scdata.end(), &indata[idx], end); idx += size; }