Repository navigation
Conversation
v01dst
requested review from
gaborbernat,
henryiii and
layday
as code owners
November 18, 2026 22:47
v01dst
added a commit
to v01dst/build
that referenced
this pull request
Nov 18, 2026
Signed-off-by: v01dst <v01dst@users.noreply.github.com>
`backend-path` entries have to stay inside the source tree (PEP 517), but `build` only checked that the entry was a directory. An entry that leaves the source tree (`..`, an absolute path) was handed to `pyproject-hooks`, which raised a bare `ValueError`. The `except BuildException` pattern shown in the API guide does not catch it, and the CLI prints a traceback before its error line. An entry that is a symlink to a directory outside the source tree was accepted, and `build` then imported the backend from outside the tree. `_validate_backend_path` now checks every entry before the hook caller is created. The containment check resolves symlinks on both sides and compares the results with `pathlib.Path.is_relative_to`, so it does not need the cross-drive special case that `os.path.commonpath` needs on Windows. The directory check runs first, so an entry that cannot be resolved at all is still reported the way it was before. Fixes pypa#1267. Refs pypa#1264. Signed-off-by: v01dst <v01dst@users.noreply.github.com>
Signed-off-by: v01dst <v01dst@users.noreply.github.com>
v01dst
force-pushed
the
fix/1264-build-exception-for-malformed-input
branch
from
November 18, 2026 23:57
234c02e to
d5fd170
Compare
Author
|
Closing this in favour of #1299, which is the same fix with the scope narrowed. I read the discussion on #1264 again before finalising this one: @henryiii picked out #1299 only changes
The other malformed inputs from #1264 are not touched. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why I made this PR
The API guide shows callers handling
BuildException, but several malformed inputs raise the raw exception from the standard library or frompackaginginstead, so that pattern does not catch them and the CLI prints a traceback before its error line. The failure mode then depends on which malformed input was handed tobuild.Description
Every malformed input is now reported as a
BuildException, which the CLI already turns into a one-line error and the documentedexcept BuildExceptionpattern catches:pyproject.tomlthat is not valid UTF-8UnicodeDecodeErrorBuildExceptionpyproject.tomlthat is a directoryIsADirectoryError(Linux),PermissionError(Windows)BuildExceptionbackend-pathentry that is absolute or leaves the source treeValueErrorfrom pyproject-hooksBuildSystemTableValidationErrorrequirespackaging.requirements.InvalidRequirementBuildExceptiontarfile.ReadErrorBuildExceptionzipfile.BadZipFileBuildExceptionNotes on the choices:
backend-pathcheck mirrors the one pyproject-hooks does (norm_and_check), so the error is raised whilebuildis still validating the[build-system]table and the message names the offending entry.failed to read source distribution ...); it was lost in 13cda2c.tarfileerror from the data filter, as before. That is a malicious archive being rejected rather than a malformed input, and the existing tests pin that behavior.pyproject.tomlas a directory raisesPermissionErroron Windows andIsADirectoryErroron Linux, so both are handled.The
BuildExceptionmessages name the file and the reason, so the CLI prints one line instead of a traceback:Changelog
docs/changelog/1298.bugfix.rst.Checklist
docs/development/contributing.rst)AI assistance (supporting detail, reviewed by the author)
The reproduction and the test cases were written with an AI coding assistant (OpenCode, MiniMax-M3.1-Flash). The author checked the behaviour of every path against the code on
mainbefore and after the change: each malformed input raised the raw exception listed in the table above before the change and raises the listedBuildExceptionafter it. The test suite was run locally with Python 3.12 on Windows (362 passed, 3 skipped).