Browse Source

Fix off-by-one memory read in binary canvas import (fixes #56, #58)

tags/v0.99.beta20
Sam Hocevar 3 years ago
parent
commit
b4b4a473cd
1 changed files with 4 additions and 1 deletions
  1. +4
    -1
      caca/codec/import.c

+ 4
- 1
caca/codec/import.c View File

@@ -420,6 +420,9 @@ ssize_t _import_bin(caca_canvas_t *cv, void const *data, size_t len)
caca_set_canvas_size(cv, 0, 0);
caca_set_canvas_size(cv, 160, len / 160);

/* Only read an even number of bytes */
len &= ~(size_t)1;

for (i = 0; i < len; i += 2)
{
caca_set_color_ansi(cv, buf[i + 1] & 0xf, buf[i + 1] >> 4);
@@ -433,6 +436,6 @@ ssize_t _import_bin(caca_canvas_t *cv, void const *data, size_t len)
}
}

return len & ~(size_t)1;
return len;
}


Loading…
Cancel
Save