Skip to content

fix(extensions): fall back to in-memory archive when the unlinked download file can't be written - #5561

Merged
mnriem merged 2 commits into
github:mainfrom
orshih6:contribot/issue-5551
Nov 25, 2026
Merged

mnriem merged 2 commits into
github:mainfrom
orshih6:contribot/issue-5551

Conversation

@orshih6

@orshih6 orshih6 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

install_extension_from_url() (used by specify extension add --from <url> and by init-time URL installs) writes the downloaded archive into an exclusively created file that has already been unlinked, then reads it back through the descriptor. Some FUSE filesystems, such as gocryptfs, reject writes and flushes to an already-unlinked inode with ENOENT. On those filesystems the command aborted with Could not safely write download file: [Errno 2] No such file or directory.

The archive is already fully buffered in memory (bounded by read_response_limited). So when writing the transient file raises OSError, the installer now closes that handle and passes an io.BytesIO of the buffered bytes to detect_archive_format() and install_from_zip(archive_file=...). The workflow installer already consumes archives this way. On filesystems that behave normally, nothing changes: the hardened, descriptor-anchored transient file is still used. I also made sure a raw descriptor isn't leaked if os.fdopen itself fails.

I kept the existing temp-file path rather than removing it. Dropping it would leave the cache-dir and leaf-creation hardening helpers, and the tests that cover them, unused, which would be a much larger change. If you'd rather always use the in-memory buffer and delete that machinery, I'm happy to do it as a follow-up.

Testing: I added test_url_install_tolerates_fs_rejecting_writes_to_unlinked_file. It makes the transient download file raise FileNotFoundError on write, the way gocryptfs does. On main it fails with the exact error from the report; with this change the install succeeds and the installer receives the original bytes. tests/specify_cli/extensions/test_command_add_path_traversal.py and tests/specify_cli/extensions/test_command_add.py pass. I could not test on a real gocryptfs mount.

AI disclosure: this change was prepared with an AI coding assistant (Claude).

🤖 Generated with Claude Code

Fixes #5551


This change was prepared with an AI coding agent (Claude) and reviewed by me before submitting. I'm happy to make any changes you'd like.

…nload file can't be written

Signed-off-by: Бат-Орших <34618353+orshih6@users.noreply.github.com>
@orshih6
orshih6 requested a review from mnriem as a code owner November 25, 2026 00:51
Copilot AI adaptive review requested due to automatic review settings November 25, 2026 00:51

Copilot AI 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.

🟡 Changes recommended

The regression tests leave buffered flush/close failures, descriptor cleanup after fdopen errors, and real fallback installation with unsafe-archive rejection unverified.

3 open issues
What changed in this PR

Adds an in-memory fallback to Spec Kit’s shared URL extension installer, addressing the gocryptfs failure in #5551 for CLI and init-time installs.

Changes:

  • Uses BytesIO when writing, flushing, or seeking the transient download file raises OSError.
  • Closes failed file handles or raw descriptors before switching to the fallback.
  • Adds a regression test for rejected writes to an already-unlinked file.

Verification was limited to source inspection and standard-library checks; project tests and a real gocryptfs mount were not exercised.

AI-generated review for the requester (identity unavailable): GitHub Copilot, model unknown, automated mode; inspection, verification, and review drafting.

File Description
tests/​specify_cli/​extensions/​test_command_add_path_traversal.py Adds write-rejection fallback coverage and verifies archive bytes reach the installer.
src/​specify_cli/​extensions/​_commands.py Adds the in-memory fallback and descriptor cleanup while preserving hardened file creation.

Review effort: Max (adaptive)

Comment thread src/specify_cli/extensions/_commands.py Resolved
… and real install via in-memory fallback

Signed-off-by: Бат-Орших <34618353+orshih6@users.noreply.github.com>
@orshih6

orshih6 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot thanks, all three were real gaps. I changed the regression test so the fake download file is now a buffered stream, and its flush fails the way gocryptfs does. Because close() also flushes, close fails too. The test is now parametrized to also cover os.fdopen raising. In both cases it checks that the stream and the raw descriptor are closed before the installer runs, and that the installer gets the original bytes. I also added test_url_install_fallback_uses_real_manager, which sends a real extension zip through the fallback and the real ExtensionManager. It checks that the valid zip installs and that a zip with a ../ member is still rejected with "Unsafe path". I checked that the new tests fail if the fdopen-path os.close or the close-error suppression is removed.

Copilot AI adaptive review requested due to automatic review settings November 25, 2026 02:33

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the archive fallback and resource-cleanup changes.

No open issues 🎉

3 resolved since last review

Review effort: Balanced (adaptive)

@mnriem mnriem added the triage-can-wait Verdict: valid and in-scope but deprioritized; held behind the evidence gate label Nov 25, 2026
@mnriem
mnriem requested a balanced review from Copilot November 25, 2026 15:01

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the buffered-archive fallback change, although the before-and-after regression comparison was not run.

No open issues 🎉

Review effort: Balanced

@mnriem
mnriem merged commit 6538403 into github:main Nov 25, 2026
14 checks passed
@mnriem

mnriem commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

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

Labels

triage-can-wait Verdict: valid and in-scope but deprioritized; held behind the evidence gate

Projects

None yet

3 participants