Repository navigation
Conversation
A "last N bytes" range on a file:// URL was not checked against the file size. With N one larger than the file, resume_from became -1, the lseek() to -1 failed and returned -1, which matched, so the transfer started at offset 0 and returned the whole file. With any larger N the lseek() result did not match and curl returned 36 without saying why. Reject the range like ftp and sftp already do, with the same message. Extend test 1020 to verify.
4490e27 to
67f0425
Compare
|
Sure, done. I folded it into test 1020 as a second transfer with |
|
Analysis of PR #23581 at 67f04254: Test ../../tests/http/test_02_download.py::TestDownload::test_02_06_download_many_parallel[h3] failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them). Generated by Testclutch |
There was a problem hiding this comment.
🟢 Approval recommended
The targeted bounds check preserves valid ranges, and the regression test covers the reported off-by-one failure.
No open issues 🎉
What changed in this PR
Makes oversized suffix ranges on file:// URLs fail consistently with a clear error, matching FTP and SFTP behavior.
Changes:
- Reject suffix ranges larger than the file before adjusting the offset, while preserving exact-size ranges.
- Extend test 1020 with a second transfer requesting one byte too many and expecting error 36.
| File | Description |
|---|---|
| tests/data/test1020 | Add regression coverage for an oversized suffix range. |
| lib/file.c | Validate the suffix offset against the file size and report a clear error. |
Review effort: Balanced
|
Thanks! |
A
-Yrange on afile://URL that asks for more bytes than the file has is handled inconsistently. With a 22 byte file:file.c adds the file size to the negative offset without checking it first. Off by one, the offset becomes -1, the lseek() to -1 fails and returns -1, and since that matches the expected offset the transfer just starts at 0. Off by more, the values no longer match and curl fails with 36 without saying why.
ftp.c and both sftp backends already reject this case with "Offset (...) was beyond file size (...)", so this adds the same check to file.c.
-r -22on the same file still returns the whole file.Test 1020 now also asks for one byte too many in a second transfer (fails before, passes after), and the existing FILE tests still pass locally.
I found this with an AI-assisted code review and then checked it by hand on a local build.