Skip to content

fix: prevent ariadne from panicking on empty stdin/file#1588

Open
daschinmoy21 wants to merge 4 commits intomolybdenumsoftware:masterfrom
daschinmoy21:fix-empty-stdin-crash-moly
Open

fix: prevent ariadne from panicking on empty stdin/file#1588
daschinmoy21 wants to merge 4 commits intomolybdenumsoftware:masterfrom
daschinmoy21:fix-empty-stdin-crash-moly

Conversation

@daschinmoy21
Copy link
Copy Markdown

Fixes oppiliappan#78

When statix receives an empty string via stdin, an empty Report is generated. Passing an empty string to ariadne's Source::from causes an index out of bounds panic. Supplying a string with a single space as a fallback prevents this panic while keeping the error location at byte offset 0.

Output after this fix-

echo "" | nix run . -- check -s

[E00] Error: Syntax error
╭─[:1:1]

1 │
· │
· ╰─ Unexpected end of file
───╯

@mightyiam
Copy link
Copy Markdown
Member

How about a test for this?

@daschinmoy21
Copy link
Copy Markdown
Author

Yea exactly i actually made a test last night. Will raise a pr in the evening after college ends

@mightyiam mightyiam force-pushed the fix-empty-stdin-crash-moly branch from 0f1a07c to 11230da Compare April 8, 2026 12:45
Comment thread bin/src/traits.rs Outdated
Comment thread bin/tests/_utils.rs Outdated
@daschinmoy21 daschinmoy21 force-pushed the fix-empty-stdin-crash-moly branch from 821c749 to 544dcf8 Compare April 9, 2026 16:57
@daschinmoy21 daschinmoy21 changed the title fix(cli): prevent ariadne from panicking on empty stdin fix: prevent ariadne from panicking on empty stdin Apr 9, 2026
Comment thread bin/tests/_utils.rs Outdated
@daschinmoy21 daschinmoy21 changed the title fix: prevent ariadne from panicking on empty stdin fix: prevent ariadne from panicking on empty stdin/file Apr 10, 2026
@mightyiam
Copy link
Copy Markdown
Member

Some conflicts

@daschinmoy21
Copy link
Copy Markdown
Author

On it

When statix receives an empty string via stdin, an empty Report is generated. Passing an empty string to ariadne's Source::from causes an index out of bounds panic. Supplying a string with a single space as a fallback prevents this panic while keeping the error location at byte offset 0.
@daschinmoy21 daschinmoy21 force-pushed the fix-empty-stdin-crash-moly branch from 544dcf8 to f8088d2 Compare April 22, 2026 20:35
@daschinmoy21
Copy link
Copy Markdown
Author

Should be good now. handles empty stdin and files now. Now it returns

[E00] Error: Syntax error
   --> <stdin>:1:1
    |
    = Unexpected end of file
[E00] Error: Syntax error
   --> empty_nix_file.nix:1:1
    |
    = Unexpected end of file

Comment thread bin/src/traits.rs
Comment on lines -52 to +56
let range = |at: TextRange| at.start().into()..at.end().into();
let src_id = path.to_str().unwrap_or("<unknown>");
if src.is_empty() {
return write_empty_stderr(writer, lint_result, src_id);
}
let range = |at: TextRange| at.start().into()..at.end().into();
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.

I'm picking up a certain smell here; isn't it strange that a LintResult exists for an empty source? I think an empty source should fail to parse. Does rnix successfully parse an empty string?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes rnix parses it. returns a ParseError::UnexpectedEOF

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.

So why are we getting this far in execution where a LintResult seems to exist?

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.

Crash when passing empty string in stdin

2 participants