Skip to content

Fix panic on BOM-prefixed files in diagnostic renderer - #30017

Merged
MichaReiser merged 3 commits into
astral-sh:mainfrom
shan3520:fix/system-buffer-bug
Nov 5, 2026
Merged

MichaReiser merged 3 commits into
astral-sh:mainfrom
shan3520:fix/system-buffer-bug

Conversation

@shan3520

@shan3520 shan3520 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

fixes #29958

Summary

When rendering diagnostics for a file with UTF-8 BOM encoding, the diagnostics renderer removes the 3 bytes of BOM from the snippet buffer, yet the annotations that started from byte 0 would underflow and fall back to their uncorrected offset, which exceeded the new length of the buffer and caused panic. The changes ensure the bounds are adjusted using saturating subtract, such that they stay within snippet bounds.

Test Plan

Added unit tests covering BOM-prefixed files and tested the minimal reproduction from the issue locally.

@shan3520
shan3520 force-pushed the fix/system-buffer-bug branch from 141f9fb to 8c4b4e3 Compare November 4, 2026 06:24
@shan3520
shan3520 marked this pull request as ready for review November 4, 2026 07:04
@shan3520
shan3520 requested a review from a team as a code owner November 4, 2026 07:04
@carljm
carljm requested a review from MichaReiser November 4, 2026 20:33

@MichaReiser MichaReiser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you

@MichaReiser
MichaReiser enabled auto-merge (squash) November 5, 2026 09:40
@MichaReiser MichaReiser added the bug An issue describing something that isn't working, or a PR that fixes a bug label Nov 5, 2026
@MichaReiser
MichaReiser merged commit 818a608 into astral-sh:main Nov 5, 2026
74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Panic] ruff format --check crashes on files starting with a UTF-8 BOM

2 participants