cute_aseprite.h: Cel Extra chunk (0x2006) is written to cels[cel_count] instead of the last cel (off-by-one, out-of-bounds write at 64 cels)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
The bug is in the 0x2006 Cel Extra case of cute_aseprite_load_from_memory in cute_aseprite.h, which indexes frame->cels[frame->cel_count] where it should use cel_count - 1. Read the Cel chunk case just above it to confirm the increment, then check how a frame with 64 cels and a trailing 0x2006 chunk is handled. Done when the extra data attaches to the correct cel, the out-of-bounds write is gone, and a zero-cel frame is rejected or skipped safely.
Written by the indexing model from the issue text.
Description
Summary
When cute_aseprite_load_from_memory parses a Cel Extra chunk (0x2006), it stores the data in frame->cels[frame->cel_count]. The preceding Cel chunk has already incremented cel_count, so this is the slot after the cel the extra data belongs to. This attaches the extra data to the wrong cel and, when a frame has 64 cels (CUTE_ASEPRITE_MAX_LAYERS), writes past the end of the cels[] array.
Affected code
cute_aseprite.h (v1.04, master 476d688):
// line 1056-1057, Cel chunk
CUTE_ASEPRITE_ASSERT(frame->cel_count < CUTE_ASEPRITE_MAX_LAYERS);
ase_cel_t* cel = frame->cels + frame->cel_count++;
...
// line 1101-1111, Cel Extra chunk
case 0x2006:
{
ase_cel_t* cel = frame->cels + frame->cel_count; // <-- should be cel_count - 1
cel->has_extra = 1;
cel->extra.precise_bounds_are_set = (int)s_read_uint32(s);
cel->extra.precise_x = s_read_fixed(s);
...
The same code is in cute_framework's copy (libraries/cute/cute_aseprite.h, 0x2006 case).
How it is reached
The Aseprite file format spec says the Cel Extra chunk "adds extra information to the latest read cel". In a normal file it directly follows a Cel chunk, so cel_count >= 1 and the right slot is cel_count - 1.
- Normal files: the extra info lands in an unused slot. The next Cel chunk in the same frame reuses that slot but does not clear
has_extra, so the extra info shows up on the wrong cel. - A frame with 64 Cel chunks (allowed: the assert checks
cel_count < 64before the increment) followed by a Cel Extra chunk writes tocels[64].cels[]is the last member ofase_frame_t, so the write lands in the next element of the heapframesarray, or past the end of the allocation for the last frame.
No assert guards this path, so it applies to debug and release builds.
Impact
Out-of-bounds heap write of 24 bytes (has_extra plus the extra struct) with values taken from the file, when loading an untrusted .ase/.aseprite file. Also a functional bug: precise bounds are reported on the wrong cel.
Suggested fix
case 0x2006:
{
if (frame->cel_count == 0) { s_skip(s, (int)chunk_size); break; } // or fail the load
ase_cel_t* cel = frame->cels + frame->cel_count - 1;
...
- Dominant language
- C
- Stars
- 5.1k
- Forks
- 316
- Avg merge
- 28m
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from RandyGaul/cute_headers
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
RandyGaul/cute_headers#445 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
RandyGaul/cute_headers#458 ·
-
Difficulty 3/5 Half a day Newbie friendliness 45/100
RandyGaul/cute_headers#457 ·
-
chunk errorOpen
Difficulty 3/5 Half a day Newbie friendliness 25/100
RandyGaul/cute_headers#446 ·
-
[cute_aseprite] Missing tag directionPossibly taken @Pituivan claimed this 73 days ago. Open
Difficulty 2/5 Under an hour Newbie friendliness 20/100
RandyGaul/cute_headers#443 ·
All issues in RandyGaul/cute_headers
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
area: services kind: bug preview-effort: small priority: low
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
new-compilers request
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
compiler-explorer/compiler-explorer#9640 ·
Maintainers usually reply within 1 day
-
Brain server leaks its session tables when it stops or cannot list the dump folderPossibly taken @marinelay claimed this today. Opentype: bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day