split: reject excessive suffix lengths#12609
Conversation
|
the Validation in comment 0 is useless ;) |
|
|
||
| // Keep this above common platform path limits while rejecting suffix lengths | ||
| // that would otherwise cause pathological filename allocation. | ||
| const MAX_SUFFIX_LENGTH: usize = 4096; |
There was a problem hiding this comment.
I picked 4096 as a conservative allocation guard, not as a semantic suffix limit.
The failure mode here is that split -a <huge> flows into filename construction and can request an absurd allocation before the filename could ever be useful. 4096 is around the common full-path limit on Linux and is already far above typical filename-component limits such as 255 bytes. Since the suffix is appended to the output prefix to form one filename component, values in the thousands are already beyond realistic portable usage, while still keeping the guard loose enough that we do not reject any plausible manual -a value.
So the tradeoff was: make the cap high enough to avoid changing normal behavior, but low enough that pathological inputs cannot allocate attacker-sized strings. If you would rather make the bound stricter and tie it to a component-oriented limit instead, I can switch this to a NAME_MAX-style value such as 255, or rename/comment it more explicitly as an allocation guard.
There was a problem hiding this comment.
ok - my point was more: it should be documented in the code :)
There was a problem hiding this comment.
Agreed. I updated the code comment so it explains that 4096 is an allocation guard rather than a semantic suffix limit, and documents the path-limit / filename-component tradeoff directly next to the constant.
That should make the choice reviewable from the code without needing the PR discussion context.
|
Makes sense. The long validation block does not add much in uutils PR openings because CI reruns the important checks and the extra command list makes the review thread harder to scan. I have removed it from this PR and will keep future uutils PR descriptions focused on the behavior change and rationale. I will only call out local validation when it explains a review question, a failing check, or a CI discrepancy. |
|
GNU testsuite comparison: |
faffe1b to
e5761ce
Compare
|
I checked the remaining red
The split-specific checks and GNU comparison are green, including the bounded-memory improvement. I tried to rerun the failed job, but GitHub rejected it because I do not have repository admin rights for reruns. I am leaving the branch unchanged rather than patching unrelated |
e5761ce to
c12fe31
Compare
Summary
split -a/--suffix-lengthvalues before filename generationFixes #12599
Notes
I did not inspect GNU coreutils source. The fix is based on the reported behavior and the local uutils failure mode: large suffix lengths could be accepted and then hang/abort while constructing output filenames.