Skip to content

fix(phar): convert extractTo warnings to RuntimeException and keep rollback under throwing error handlers - #1201

Open
rootsiemen wants to merge 1 commit into
crazy-goat:masterfrom
rootsiemen:fix-1181-extractto-rollback
Open

rootsiemen wants to merge 1 commit into
crazy-goat:masterfrom
rootsiemen:fix-1181-extractto-rollback

Conversation

@rootsiemen

Copy link
Copy Markdown
Contributor

Closes #1181

ZipArchive::extractTo() emits an E_WARNING on failure. With a strict error handler installed (e.g. Symfony ErrorHandler, which throws ErrorException), the warning bypassed the catch (\RuntimeException) rollback in extractToDirectory() and the archive cleanup in fetch(), so a failed extraction left the pre-extracted entries and the bad archive on disk.

  • extractToDirectory() now suppresses the warning with @ and converts the failure into a RuntimeException that names the entry and carries the underlying warning text (same idiom as writeStream()).
  • The cleanup catches in extractToDirectory() and fetch() are widened to \Throwable and rethrow, so rollback and archive removal still happen even if a handler throws despite the suppression.
  • The four [Tests] SfxDownloader: extraction rollback error paths are not tested #933 rollback tests no longer hide warnings behind @fetch(); they run through a runWithoutWarningLeak() helper that fails if any warning escapes fetch().
  • New regression test testExtractZipRollsBackAndRemovesArchiveUnderThrowingErrorHandler installs an unconditionally throwing handler and asserts the failed archive is removed and the earlier entry is rolled back (verified to fail on the old code: the archive stayed on disk).

Verified locally: tests/Phar/SfxDownloaderTest.php 69 tests green, composer lint green except pre-existing shellcheck (untouched bin/worktree-done.sh) and missing hadolint in this environment.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] ZipArchive::extractTo() warning escapes as ErrorException and skips SfxDownloader rollback and archive cleanup

1 participant