fix out-of-bounds read in json path ReadKey lookahead by jmestwa-coder · Pull Request #23371 · duckdb/duckdb · GitHub
Skip to content

fix out-of-bounds read in json path ReadKey lookahead - #23371

Merged
Mytherin merged 1 commit into
duckdb:v1.5-variegatafrom
jmestwa-coder:json-path-readkey-bound
Jun 23, 2026
Merged

Mytherin merged 1 commit into
duckdb:v1.5-variegatafrom
jmestwa-coder:json-path-readkey-bound

Conversation

@jmestwa-coder

Copy link
Copy Markdown
Contributor

Two lookahead reads in the JSON path parser (ReadKey) run one byte past the path while only one byte is guaranteed left:

  • the ** wildcard check reads *(ptr + 1), hitting *end when * ends the path
  • the recursive . branch reads the same byte, then walks ptr past end

Reachable from a non-constant path arg whose string_t is non-inlined (> 12 bytes, so not null-terminated), e.g. json_extract(j, '$.aaaaaaaaaaaa.*'). ASan flags a heap-buffer-overflow read of size 1 in ReadKey. Constant paths come from a null-terminated copy and are unaffected. Bounded both lookaheads against end and reject a trailing recursive ..

@duckdb-draftbot
duckdb-draftbot marked this pull request as draft June 19, 2026 06:53
@Mytherin

Copy link
Copy Markdown
Member

@jmestwa-coder
jmestwa-coder force-pushed the json-path-readkey-bound branch from a7395a2 to a9c330c Compare June 22, 2026 13:39
@jmestwa-coder
jmestwa-coder changed the base branch from main to v1.5-variegata June 22, 2026 13:39
@jmestwa-coder

Copy link
Copy Markdown
Contributor Author

rebased onto v1.5-variegata and retargeted the PR. the fix and both test cases carried over cleanly.

@Mytherin
Mytherin marked this pull request as ready for review June 22, 2026 15:33
@Mytherin
Mytherin merged commit c9c0950 into duckdb:v1.5-variegata Jun 23, 2026
65 checks passed
@Mytherin

Copy link
Copy Markdown
Member

kaka11chen pushed a commit to kaka11chen/astrovela_vane that referenced this pull request Aug 14, 2026
…23371)

Two lookahead reads in the JSON path parser (ReadKey) run one byte past
the path while only one byte is guaranteed left:
- the `**` wildcard check reads `*(ptr + 1)`, hitting `*end` when `*`
ends the path
- the recursive `.` branch reads the same byte, then walks ptr past end

Reachable from a non-constant path arg whose string_t is non-inlined (>
12 bytes, so not null-terminated), e.g. `json_extract(j,
'$.aaaaaaaaaaaa.*')`. ASan flags a heap-buffer-overflow read of size 1
in ReadKey. Constant paths come from a null-terminated copy and are
unaffected. Bounded both lookaheads against end and reject a trailing
recursive `.`.

Upstream-Commit: duckdb/duckdb@c9c0950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants