Skip to content

fix: revert simd to json#222

Merged
SyMind merged 3 commits intomainfrom
fix-source-root-to-json
Mar 6, 2026
Merged

fix: revert simd to json#222
SyMind merged 3 commits intomainfrom
fix-source-root-to-json

Conversation

@SyMind
Copy link
Collaborator

@SyMind SyMind commented Mar 5, 2026

This pull request correctly addresses the issue of file and sourceRoot not being properly JSON-escaped by using escape_into when constructing the JSON string. While this mitigates a JSON injection vulnerability for these fields, the fix is incomplete as mappings and debugId are still untrusted strings serialized without escaping, leaving the application vulnerable to JSON injection. The capacity calculation for max_segments and total_string_bytes has been adjusted for the currently escaped fields, but it will need further updates to accurately account for the potential increase in size when mappings and debugId are also escaped.

Copilot AI review requested due to automatic review settings March 5, 2026 12:03
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 5, 2026

Merging this PR will degrade performance by 48.98%

❌ 2 regressed benchmarks
✅ 9 untouched benchmarks
⏩ 7 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
source_map_to_json 8.3 ms 16.3 ms -48.98%
concat_generate_string_with_cache 9.8 µs 13.8 µs -28.79%

Comparing fix-source-root-to-json (8f3f11d) with main (a889162)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical fix in the sourcemap serialization logic. It ensures that the file and sourceRoot fields are correctly JSON-escaped, preventing the generation of malformed JSON output. Additionally, it refines the internal string length calculations for these fields, improving the accuracy of memory pre-allocation during the serialization process.

Highlights

  • JSON Escaping: Implemented proper JSON escaping for the file and sourceRoot fields when serializing a sourcemap to JSON, preventing malformed output.
  • Length Calculation Refinement: Adjusted string length calculations to accurately account for the file and sourceRoot fields, moving their length contribution from max_segments to total_string_bytes for improved memory pre-allocation.
  • Conditional Check Refactoring: Refactored conditional checks for the presence of file and sourceRoot to use is_some() for clarity in initial length estimations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/to_json.rs
    • Applied JSON escaping to the file and sourceRoot values using escape_into.
    • Updated the max_segments calculation to exclude the variable length of file and sourceRoot strings.
    • Included the lengths of file and sourceRoot strings in the total_string_bytes calculation.
    • Refactored if let Some checks to is_some() for optional fields in initial length estimation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses the issue of file and sourceRoot not being properly JSON-escaped by using escape_into when constructing the JSON string. While this mitigates a JSON injection vulnerability for these fields, the fix is incomplete as mappings and debugId are still untrusted strings serialized without escaping, leaving the application vulnerable to JSON injection. The capacity calculation for max_segments and total_string_bytes has been adjusted for the currently escaped fields, but it will need further updates to accurately account for the potential increase in size when mappings and debugId are also escaped.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates SourceMap::to_json() serialization to ensure optional file and sourceRoot fields are JSON-escaped, and adjusts the preallocation accounting to include these optional strings in the total escaped-length estimate.

Changes:

  • Adjust max_segments accounting for optional file / sourceRoot fields.
  • Include file / sourceRoot in total_string_bytes used for worst-case escaping capacity estimation.
  • Switch file / sourceRoot output from raw push to json_escape_simd::escape_into(...).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SyMind SyMind force-pushed the fix-source-root-to-json branch from a838061 to 534a81d Compare March 5, 2026 12:16
@SyMind SyMind changed the title fix: source root and file should be escape fix: revert simd to json Mar 5, 2026
@SyMind SyMind requested a review from Copilot March 5, 2026 12:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SyMind SyMind force-pushed the fix-source-root-to-json branch 2 times, most recently from 0751374 to 534a81d Compare March 6, 2026 02:42
@SyMind SyMind force-pushed the fix-source-root-to-json branch 7 times, most recently from 0cfff49 to e7174c5 Compare March 6, 2026 06:20
@SyMind SyMind merged commit 41aa226 into main Mar 6, 2026
7 of 8 checks passed
@SyMind SyMind deleted the fix-source-root-to-json branch March 6, 2026 06:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants