fix(events): stop event run crashing on every piped stdin payload - #4326
Open
Noor-ul-ain001 wants to merge 1 commit into
Open
fix(events): stop event run crashing on every piped stdin payload#4326Noor-ul-ain001 wants to merge 1 commit into
event run crashing on every piped stdin payload#4326Noor-ul-ain001 wants to merge 1 commit into
Conversation
`event_run` (src/specify_cli/commands/event.py) capped its stdin read at 1 MiB to prevent a DoS (github#3857), but the truncation check reads a `.eof` attribute that does not exist on any Python file-like object, including `sys.stdin` (`hasattr(sys.stdin, "eof")` is False). Every piped-stdin invocation raised `AttributeError: '...' object has no attribute 'eof'` instead of running — piped stdin is the command's documented primary use case (a native hook feeds it a JSON payload this way), and `isatty()` is False whenever stdin isn't an interactive terminal, so this fired on essentially every real invocation, not just oversized ones. Even the intended oversized-payload branch was broken a second way: `typer.Exit(code=1, message=...)` — `typer.Exit.__init__` only accepts `code`, not `message` — so that path raised `TypeError` instead of the documented clean error. Fix: detect truncation the standard way (read one more byte once the cap is hit; a non-empty result means more data was waiting beyond it), and report the oversized-payload error via `typer.echo(..., err=True)` before `raise typer.Exit(code=1)`. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FW9fAYsCBCAgdKWovtSyqt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
event_run(src/specify_cli/commands/event.py) capped its stdin read at 1 MiB to prevent a DoS (fix: cap stdin read at 1 MiB to prevent DoS #3857), but the truncation check readssys.stdin.eof— that attribute does not exist on any Python file-like object, includingsys.stdin(hasattr(sys.stdin, "eof")isFalse).AttributeError: '...' object has no attribute 'eof'instead of running. Piped stdin is this command's documented primary use case ("Resolve and run an event-driven command script with stdin payload" — a native hook feeds it a JSON payload this way), andisatty()isFalsewhenever stdin isn't an interactive terminal, so this fired on essentially every real invocation, not only oversized ones — the fix: cap stdin read at 1 MiB to prevent DoS #3857 DoS fix left the feature entirely broken.raise typer.Exit(code=1, message="...")—typer.Exit.__init__accepts onlycode(verified viainspect.signature), notmessage— so that path raisedTypeErrorinstead of the documented clean error.typer.echo(..., err=True)beforeraise typer.Exit(code=1).Test plan
tests/test_event_command.py(no prior test coverage existed for this command): a normal piped payload reaches the handler intact, a TTY/no-stdin invocation falls back to"{}", and an oversized piped payload exits 1 with the limit message instead of crashing.AttributeError('...' object has no attribute 'eof')on every case, including the "no stdin" one (confirmsisatty()isFalseunder non-interactive invocation, matching real hook usage) — and pass with it.Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01FW9fAYsCBCAgdKWovtSyqt