Skip to content

fix(libcurl): resolve curl_mime_filedata paths in the guest file namespace - #24585

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
mauroalvare:fix/libcurl-mime-filedata-guest-path
Nov 21, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
mauroalvare:fix/libcurl-mime-filedata-guest-path

Conversation

@mauroalvare

Copy link
Copy Markdown
Contributor

What

curl_mime_filedata passed the guest's path straight to the bundled curl 7.81.0, whose curl_mime_filedata runs stat and access on it and later fopens it. Those are host calls, so a guest path such as /app0/upload.bin or /data/report.dmp was looked up at the host root (C:\app0\upload.bin on Windows, /app0/upload.bin on Linux): the call returned CURLE_READ_ERROR, or, if a host file happened to exist at that path, curl sent the host file. libc's fopen and FreeType's FT_New_Face already resolve guest paths with ResolvePathError_nid_no_patch; this export did not.

Now:

  • the guest path is resolved as fopen resolves it, and curl is given the host path, so it stats, sizes and reads the file the guest named;
  • the part's file name, which curl takes from the base name of the path it is given, is set to the guest libc basename of the guest path, the name the console's curl would derive, rather than the base name of the host path;
  • a guest path that does not resolve (a name over 255 bytes, a missing mount) gives curl an empty name, which fails stat on every host, so the part ends up as curl leaves any file it cannot stat: a file part that fails when opened, and CURLE_READ_ERROR;
  • a null part or name keeps going to curl unchanged.

A base name too long for basename's 1024-byte buffer throws: there FreeBSD's basename returns null and curl passes it to strdup.

The debt fragment records what is still open: whether the console's curl uses basename(3) or curl's own Curl_basename (which also splits at \), the ANSI-only file API of the Windows backend, and the paths that still go to curl untranslated (CURLFORM_FILE, CURLFORM_FILECONTENT, and options such as CURLOPT_CAINFO and CURLOPT_COOKIEFILE).

Tested

Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. Branch head 73a7a97879 on main c8d5f91168.

  • New TestMimeFileGuestPath in core/libs/prx/libcurl/tests/CurlTransfers.cpp (guest_curl_transfers): writes a file through guest fopen at /anyps5-curl-mime-<n>.bin, attaches it with curl_mime_filedata, posts the form to the test's loopback server and checks the part's body bytes and Content-Disposition: form-data; name="upload"; filename="anyps5-curl-mime-<n>.bin". It also checks CURLE_READ_ERROR for a missing guest file and for a 300-byte name that does not resolve, and that such a part can then be given data and sent.
  • With only the test applied (on main c8f72e905c), guest_curl_transfers fails at the curl_mime_filedata call for the guest path. With the change it passes.
  • ctest -R curl: the 11 libcurl tests pass after the rebase onto c8d5f91168. guest_curl_slistmime, which attaches a file by a relative name, still passes: a relative guest name resolves against the guest working directory, which is the host's in that test.
  • python tools/check_conventions.py --base origin/main, python tools/debt_fold.py --check and git diff --check origin/main...HEAD: clean.
  • python tools/pr_overlap.py --names curl_mime_filedata: main implements it, no open pull request touches it. python tools/pr_overlap.py --branch fix/libcurl-mime-filedata-guest-path lists fix(libcurl): pass CURLOPT_HTTPPOST forms to curl as host nodes #24542 (CURLOPT_HTTPPOST host nodes), which adds its own transfer test at the same two places in CurlTransfers.cpp (before main and after TestMimeBase64Transfer();): a textual overlap with no shared export, so whichever lands second rebases. It could not compare feat(libcurl): implement curl_formget #17661 (curl_formget, conflicting with main); its Export.cpp hunks are in the form helpers and curl_formadd, not near this export or the includes.
  • Not run on Linux or macOS, and no title was run. The Linux behaviour before the change follows from the same code path (curl stats /anyps5-curl-mime-<n>.bin at the host root); it was not run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

…space

curl_mime_filedata handed the guest path to the host curl, which ran
stat and fopen on it as a host path. /app0/... or /data/... was looked
up at the host root, so the part failed with CURLE_READ_ERROR, or a
host file at that path was sent.

The path is now resolved as fopen resolves it, curl opens the host
path, and the part's file name is the guest libc basename of the guest
path, as curl takes it from the path it is given. A path that does not
resolve leaves a file part that cannot be opened and returns
CURLE_READ_ERROR, like a path that fails stat.

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 73a7a97879:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_curl_Transfers_tests built cleanly.
  • CTest (guest_curl_transfers):
    1/1 Test #5573: guest_curl_transfers .............   Passed    0.04 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libcurl/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5573: guest_curl_transfers .............***Failed    0.13 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified null safety in curl_mime_filedata_nid_postfix: if !part || !filename, delegates directly to host ::curl_mime_filedata(part, filename) and maintains part cleanup via ReplacePartContent
    • Verified basename extraction: checked basename_r_nid_postfix(filename, base) buffer handling (1024 bytes) and length error throwing behavior conforming to FreeBSD/curl semantics
    • Verified path resolution: checked ResolvePathError_nid_no_patch(filename, host) usage, handling unresolved guest paths by passing empty string to ::curl_mime_filedata which triggers stat failure and CURLE_READ_ERROR as expected
    • Verified mime filename overriding: checked ::curl_mime_filename(part, base) setting the part filename to the guest basename rather than host path, and verified return code precedence when named != CURLE_OK
    • Verified AGENTS.md compliance: debt fragment added under docs/dev/debt/changes/, conventional commit guidelines followed, no disallowed comments or special casing

Looks Good To Me

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed — no blocking findings

The changed code appears consistent with the stated guest path handling, but I could not run the reported checks in this review environment.

What I ran

Inspected head 73a7a97879d28e3a882b96fddb2ee5d645d50e39 using repo_read.py for the prepared description, commit summary, manifest, diff, changed code hunks, and relevant helpers. No commands or tests were run.

Results

Check Result Note
Changed code review passed Three changed files inspected
Automated checks not run No test execution available
Author-reported checks not run Windows test results are in the PR description

Findings

Blocking

None.

Non-blocking

None.

Not verified

The full contents of core/libs/prx/libcurl/Export.cpp and core/libs/prx/libcurl/tests/CurlTransfers.cpp were not read; only the changed hunks and directly relevant helpers were inspected. Linux and macOS behavior, and console curl basename behavior, remain unverified as noted in the PR description. The review folder's files.json was unavailable; manifest.json lists three changed files, all included. I read relevant sections of all three changed files.

To get this to a good state

Nothing is required. Optional: run the described tests on the target platforms and confirm console curl filename behavior.

@oneandonlydean
oneandonlydean merged commit b7aa857 into boykopovar:main Nov 21, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants