google / wuffs

Wrangling Untrusted File Formats Safely
Other
4.16k stars 131 forks source link

print-image-metadata script can go into an infinite loop #107

Closed dev0x13 closed 1 year ago

dev0x13 commented 1 year ago

Here is the problematic PNG:

If I understand correctly, this can be fixed by rewriting this code:

uint64_t n0 = r.max_excl - src->reader_position();
if (n0 == 0) {
  break;
}
uint64_t n1 = src->reader_length();
uint64_t n = wuffs_base__u64__min(n0, n1);

into this code:

uint64_t n0 = r.max_excl - src->reader_position();
uint64_t n1 = src->reader_length();
uint64_t n = wuffs_base__u64__min(n0, n1);
if (n == 0) {
  break;
}