- if (bytestream_get_le16(&buf)) {
- while (buf_end - buf >= 6) {
- const uint8_t *buf_pend = buf + FFMIN(AV_RL16(buf), buf_end - buf);
- //ignore uncompressed block size reported at buf[2]
- int marker = buf[4];
- buf += 5;
-
- while (plane < s->nb_planes && buf_pend - buf >= 1) {
+ if (bytestream2_get_le16(&s->g)) {
+ while (bytestream2_get_bytes_left(&s->g) >= 6) {
+ int stop_size, marker, t1, t2;
+
+ t1 = bytestream2_get_bytes_left(&s->g);
+ t2 = bytestream2_get_le16(&s->g);
+ stop_size = t1 - FFMIN(t1, t2);
+ // ignore uncompressed block size
+ bytestream2_skip(&s->g, 2);
+ marker = bytestream2_get_byte(&s->g);
+
+ while (plane < s->nb_planes &&
+ bytestream2_get_bytes_left(&s->g) > stop_size) {