Repository navigation
fix: reject slorp into a zero-capacity rant instead of overflowing (#377) - #393
Merged
leo-aa88 merged 1 commit intoOct 10, 2026
Conversation
…rainrotlang#377) stdrot_slorp fabricated a 1024-byte capacity for an empty rant and handed it to fgets, writing up to 1023 bytes past the real allocation. Pass the true len instead: input_string() already returns INPUT_BUFFER_OVERFLOW for buffer_size <= 1 without touching the buffer, so the read now fails with the same graceful error as a sized buffer. Adds regression fixtures for the long-input repro and the short-input edge case.
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.
Description
stdrot_slorp'sSTDROT_STRINGcase fabricated a 1024-byte capacity whenever the passed rant hadlen == 0and handed that toslorp_string()→fgets, writing up to 1023 bytes past the empty string's actual allocation (heap-buffer-overflow; reproduced as an access violation with corrupted heap contents on Windows, ASan report in the issue on Linux).The fix removes the fabrication and always passes the rant's real
len.input_string()already returnsINPUT_BUFFER_OVERFLOWforbuffer_size <= 1without touching the buffer (lib/input.c), so a zero-capacity rant now fails with the same gracefulError: Input exceeded buffer size.that a sizedyap buf[8]produces — exactly the rejection behavior offered in the issue. Sized buffers (len >= 2) pass through unchanged, so all existing slorp behavior is preserved.Tests added (CONTRIBUTING.md, "TESTS ARE MANDATORY"):
test_cases/slorp_empty_rant_fail— the issue's repro: 200-byte adversarial input intorant s = ""must produce the graceful error, never an out-of-bounds write. Fails before the patch (crash/corruption), passes after.test_cases/slorp_empty_rant_short_input_fail— edge case: even a 2-byte line cannot fit capacity 0, so it must also be rejected gracefully rather than written.tests/expected_results.jsonandtests/stdin_fixtures.json(generated programmatically; A-count asserted to be exactly 200).Local verification (Windows/MSYS2, MinGW-w64 gcc 16.2):
make windows— clean under-Werror.93 failed, 414 passed; after fix93 failed, 416 passed— the two new fixtures pass, and the 93 failures are a byte-identical set before and after (pre-existing Windows-only environment failures: dlopen/#cookedmodule fixtures and/proc/self/exetests that require Linux; noslorpstdin fixture fails on either side).0xC0000005access violation (heap overwritten with the input); afterexit=1,Error: Input exceeded buffer size.make format-check(clang-format 15.0.7, the pinned version) andmake cppcheck(2.21.0) both pass.Disclosure per AGENTS.md/CONTRIBUTING expectations: the code change and the test fixtures in this PR were drafted with AI coding assistance; I reviewed them against
lib/input.c's overflow contract and the issue discussion, and I ran the build, fixture-suite baseline comparison, format and cppcheck gates locally myself.make valgrind/ASan cannot run on a Windows box — please rely on the Linux CI jobs for the sanitizer/valgrind legs.Related Issue
Fixes #377
Type of Change
Checklist
test_cases/*.brainrotfor language-visible behavior; a host-side C test wired intomake testfor internal APIs Brainrot source cannot reach). Required for every bug fix, feature, refactor, performance change, and breaking change — not optional, not "if applicable". See CONTRIBUTING.md ("TESTS ARE MANDATORY").make format-checklocally (ormake formatto fix)