Skip to content

tool_cb_hdr: do not truncate existing file on filename-less C-D header - #23501

Closed
matty69v wants to merge 1 commit into
curl:masterfrom
matty69v:oj-cd-truncate
Closed

matty69v wants to merge 1 commit into
curl:masterfrom
matty69v:oj-cd-truncate

Conversation

@matty69v

Copy link
Copy Markdown
Contributor

With -O -J, a Content-Disposition header without a usable filename (for example "inline") made curl create the URL-derived output file right away. When a later Content-Disposition header then named that same file, the no-clobber check refused it, but the file had already been truncated to zero bytes. The same happened when such a header came in a 3xx response before the Location: header with -L.

This defers creating the output file until the body arrives (or the transfer ends), like for any other header. Buffered headers for -i are written at that point.

Tests 1717, 1718 and 1719 cover -OJ, -OJi and -OJL. All three fail without the fix

Copilot AI balanced review requested due to automatic review settings October 20, 2026 08:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Successful zero-body responses discard buffered headers despite -i.

1 open issue
What changed in this PR

Defers curl output-file creation for filename-less Content-Disposition headers to prevent premature truncation with -OJ.

Changes:

  • Removes eager file creation and buffered-header writes.
  • Adds regression tests for existing-file preservation with -OJ, -OJi, and -OJL.
File Description
tests/​data/​test1719 Tests existing-file preservation across redirects.
tests/​data/​test1718 Tests preservation with included headers.
tests/​data/​test1717 Tests preservation with successive Content-Disposition headers.
tests/​data/​Makefile.am Registers the three regression tests.
src/​tool_cb_hdr.c Defers output creation for filename-less headers.

Review effort: Balanced

Comment thread src/tool_cb_hdr.c Resolved
@matty69v

Copy link
Copy Markdown
Contributor Author

@bagder I can't assign you as reviewer

Comment thread tests/data/Makefile.am Outdated
test1716 \
test1717 \
test1718 \
test1719 \

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 suggest condensing into a single test, or even better include it in an existing one.

@testclutch

Copy link
Copy Markdown

Analysis of PR #23501 at 8c091146:

Test ../../tests/http/test_22_httpsrr.py::TestHTTPSRR::test_22_01_httpsrr_h1[DoH] 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).

Test ../../tests/http/test_22_httpsrr.py::TestHTTPSRR::test_22_02_httpsrr_h3[DoH] 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).

Test ../../tests/http/test_22_httpsrr.py::TestHTTPSRR::test_22_03_httpsrr_h3[DoH] 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).

Test ../../tests/http/test_22_httpsrr.py::TestHTTPSRR::test_22_04_httpsrr_wrong_target[DoH] 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).

Test ../../tests/http/test_22_httpsrr.py::TestHTTPSRR::test_22_05_httpsrr_no_default_alpn[DoH] 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).

Test ../../tests/http/test_22_httpsrr.py::TestHTTPSRR::test_22_06_httpsrr_proxy[DoH] 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).

Test ../../tests/http/test_30_vsftpd.py::TestVsFTPD::test_30_04_download_10_parallel[data-10m] failed, but it has been 0.2% flaky lately, so it's probably NOT a fault of the PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them). Note that this CI job has had a number of other flaky tests recently (4, to be specific) so it may be that this failure is rather a systemic issue with this job and not with this specific PR.

There are more failures, but that's enough from Gha.

Generated by Testclutch

@matty69v

Copy link
Copy Markdown
Contributor Author

@vszakats is it better like this ?

@matty69v
matty69v requested a review from vszakats October 20, 2026 17:25
@bagder

bagder commented Oct 22, 2026

Copy link
Copy Markdown
Member

@matty69v can you take a look at the merge conflicts in here and force-push?

With -O -J, a Content-Disposition header without a usable filename
(for example "inline") made curl create the URL-derived output file
right away. When a later Content-Disposition header then named that
same file, the no-clobber check refused it, but the file had already
been truncated to zero bytes. The same happened when such a header came
in a 3xx response before the Location: header with -L.

Defer creating the output file until the body arrives (or the transfer
ends), like for any other header. When the transfer ends without a body,
also write the headers buffered for -i, which were lost before.

Test 1718 verifies both.
@matty69v

Copy link
Copy Markdown
Contributor Author

@bagder Done: rebased on master and force-pushed. The test moved to 1718 since 1717 is now taken.

@matty69v
matty69v requested a lite review from Copilot October 22, 2026 16:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Move xattr handling after deferred file creation and add or clarify regression coverage for the plain -OJ and redirect cases.

2 open issues
1 resolved since last review

Review effort: Lite

Comment thread src/tool_operate.c Resolved
Comment thread tests/data/Makefile.am Resolved
@bagder

bagder commented Oct 23, 2026

Copy link
Copy Markdown
Member

Thanks!

vszakats added a commit that referenced this pull request Oct 23, 2026
Test results with #23571 reverted:
```
data/test301 has too many '<data>' tags (2 vs. 1 maximum)
data/test702 has too many '<features>' tags (2 vs. 1 maximum)
data/test714 has too many '<features>' tags (2 vs. 1 maximum)
data/test715 has too many '<features>' tags (2 vs. 1 maximum)
data/test1718 has superfluous comment: '# Client-side'
data/test1718 has superfluous comment: '# Verify data after the test has been "shot"'
data/test1456 has too many '<features>' tags (2 vs. 1 maximum)
data/test1800 has too many '<features>' tags (2 vs. 1 maximum)
data/test3202 has too many '<features>' tags (2 vs. 1 maximum)
Error: Process completed with exit code 9.
```
Ref: https://github.com/curl/curl/actions/runs/39865646942/job/120127058099?pr=23573#step:44:32

Also:
- test1337: delete stray `>`.
- test1718: delete superfluous comments.
  Follow-up to 631ed30 #23501

Follow-up to 95f8e3a #23571
Follow-up to ffca9f6 #23562

Closes #23573
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

5 participants