Skip to content

refactor(napi/parser, linter/plugins): improve safety of raw transfer interface#22424

Merged
graphite-app[bot] merged 1 commit into
mainfrom
om/05-14-refactor_napi_parser_linter_plugins_improve_safety_of_raw_transfer_interface
May 14, 2026
Merged

refactor(napi/parser, linter/plugins): improve safety of raw transfer interface#22424
graphite-app[bot] merged 1 commit into
mainfrom
om/05-14-refactor_napi_parser_linter_plugins_improve_safety_of_raw_transfer_interface

Conversation

@overlookmotel

@overlookmotel overlookmotel commented May 14, 2026

Copy link
Copy Markdown
Member

Add a check that the input passed to raw transfer parser implementations is valid - both in napi/parser and in the raw transfer implementation used in Oxlint's RuleTester.

Check that source_start and source_len which are passed from JS side are within bounds of the active region of the Arena. This check is not strictly necessary - it's part of the safety contract, and is enforced on JS side - but it's critical as the setup of the Arena on Rust side depends on the accuracy of these values. If they were wrong, it could lead to reading/writing out of bounds. The check is cheap, so it seems worthwhile - safety trumps the tiny perf impact here.

The 3rd invariant of these functions is that the bytes in the buffer between source_start and source_start + source_len represent a valid UTF-8 string. Here a full runtime check isn't appropriate, as it would involve scanning and validating the whole source text string (expensive). But do enable the full check in debug builds (used by raw transfer parser tests, and Oxlint conformance tests).

overlookmotel commented May 14, 2026

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@overlookmotel overlookmotel marked this pull request as ready for review May 14, 2026 14:39
@overlookmotel overlookmotel requested a review from camc314 as a code owner May 14, 2026 14:39
Copilot AI review requested due to automatic review settings May 14, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds defensive runtime bounds checking on source_start/source_len (always) and full UTF-8 validation in debug builds for the raw transfer parser entry points in both napi/parser and Oxlint's JS plugin parser, hardening the safety contract of these unsafe fns.

Changes:

  • Add assert!(source_end <= ACTIVE_SIZE) in both raw-transfer parse implementations.
  • Replace unconditional from_utf8_unchecked with cfg!(debug_assertions)-gated full UTF-8 validation, falling back to unchecked in release.
  • Hoist source_start/source_end computation to a single place to avoid duplication.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
napi/parser/src/raw_transfer.rs Adds active-region bounds assertion and debug-only UTF-8 validation around source slice access.
apps/oxlint/src/js_plugins/parse.rs Mirrors the same defensive checks in Oxlint's JS plugin raw-transfer parser.

@overlookmotel overlookmotel force-pushed the om/05-13-refactor_napi_parser_raw_transfer_store_source_text_at_end_of_buffer branch from 62e44cc to 7e21af0 Compare May 14, 2026 18:15
@overlookmotel overlookmotel force-pushed the om/05-14-refactor_napi_parser_linter_plugins_improve_safety_of_raw_transfer_interface branch from dd2abb0 to 3c4ebd0 Compare May 14, 2026 18:15
@overlookmotel overlookmotel self-assigned this May 14, 2026
@overlookmotel overlookmotel force-pushed the om/05-14-refactor_napi_parser_linter_plugins_improve_safety_of_raw_transfer_interface branch from 3c4ebd0 to fdd60fa Compare May 14, 2026 18:28
@overlookmotel overlookmotel force-pushed the om/05-13-refactor_napi_parser_raw_transfer_store_source_text_at_end_of_buffer branch 2 times, most recently from 0f1fb87 to eebf4df Compare May 14, 2026 21:15
@overlookmotel overlookmotel force-pushed the om/05-14-refactor_napi_parser_linter_plugins_improve_safety_of_raw_transfer_interface branch from fdd60fa to ba20cd2 Compare May 14, 2026 21:15
@graphite-app

graphite-app Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Merge activity

… interface (#22424)

Add a check that the input passed to raw transfer parser implementations is valid - both in `napi/parser` and in the raw transfer implementation used in Oxlint's `RuleTester`.

Check that `source_start` and `source_len` which are passed from JS side are within bounds of the active region of the `Arena`. This check is not strictly necessary - it's part of the safety contract, and is enforced on JS side - but it's critical as the setup of the `Arena` on Rust side depends on the accuracy of these values. If they were wrong, it could lead to reading/writing out of bounds. The check is cheap, so it seems worthwhile - safety trumps the tiny perf impact here.

The 3rd invariant of these functions is that the bytes in the buffer between `source_start` and `source_start + source_len` represent a valid UTF-8 string. Here a full runtime check isn't appropriate, as it would involve scanning and validating the whole source text string (expensive). But _do_ enable the full check in debug builds (used by raw transfer parser tests, and Oxlint conformance tests).
@graphite-app graphite-app Bot force-pushed the om/05-13-refactor_napi_parser_raw_transfer_store_source_text_at_end_of_buffer branch from eebf4df to c2c8f80 Compare May 14, 2026 22:29
@graphite-app graphite-app Bot force-pushed the om/05-14-refactor_napi_parser_linter_plugins_improve_safety_of_raw_transfer_interface branch from ba20cd2 to e3b0d54 Compare May 14, 2026 22:30
Base automatically changed from om/05-13-refactor_napi_parser_raw_transfer_store_source_text_at_end_of_buffer to main May 14, 2026 22:36
@graphite-app graphite-app Bot merged commit e3b0d54 into main May 14, 2026
28 checks passed
@graphite-app graphite-app Bot deleted the om/05-14-refactor_napi_parser_linter_plugins_improve_safety_of_raw_transfer_interface branch May 14, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter A-parser Area - Parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants