Skip to content

Fix heap-buffer-overflow during GC of an externally-backed SharedArrayBuffer - #5312

Open
PGZXB wants to merge 1 commit into
jerryscript-project:masterfrom
PGZXB:fix-issue-5272
Open

PGZXB wants to merge 1 commit into
jerryscript-project:masterfrom
PGZXB:fix-issue-5272

Conversation

@PGZXB

@PGZXB PGZXB commented Sep 25, 2026

Copy link
Copy Markdown

Externally-backed ArrayBuffer/SharedArrayBuffer objects wrap a caller-supplied
buffer. When no array-buffer free callback is registered, garbage collection
returns such a buffer to the JerryScript heap free list through
jmem_heap_free_block_internal(). Its free-list linking writes the block header
(size / next_offset) into the buffer, which runs past the end of buffers
smaller than a free block:

WRITE of size 4 at 0x502000000014
    #0 jmem_heap_free_block_internal jerry-core/jmem/jmem-heap.c:436
    #1 ecma_gc_run jerry-core/ecma/base/ecma-gc.c
0x502000000017 is located 0 bytes after 7-byte region

Mark externally-supplied buffers with a dedicated flag and skip the internal
heap free for them when no free callback is registered. Registered free
callbacks are still invoked, and the buffer is still treated as allocated so
lazy allocation does not replace the caller's buffer.

Fixes #5272

JerryScript-DCO-1.0-Signed-off-by: PGZXB pgzxb@qq.com

…yBuffer

Externally-backed ArrayBuffer/SharedArrayBuffer objects wrap a caller-supplied
buffer. When no array-buffer free callback is registered, garbage collection
returns such a buffer to the JerryScript heap free list through
jmem_heap_free_block_internal(). Its free-list linking writes the block header
into the buffer, which runs past the end of buffers smaller than a free block.

Mark externally-supplied buffers with a dedicated flag and skip the internal
heap free for them when no free callback is registered. Registered free
callbacks are still invoked, and the buffer is still treated as allocated so
lazy allocation does not replace the caller's buffer.

Fixes jerryscript-project#5272

JerryScript-DCO-1.0-Signed-off-by: PGZXB <pgzxb@qq.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Heap-overflow (write) during garbage collection of an externally-backed SharedArrayBuffer

1 participant