Repository navigation
Conversation
…-character With errors="strict", tarfile could not read an archive whose ustar name, linkname, uname or gname field holds a value cut in the middle of a multibyte character, even when a GNU longname or longlink header or a pax header (extended or global) replaces that field. Such fields are written for paths longer than 100 bytes, for example by tarfile itself with GNU_FORMAT and by GNU tar and bsdtar in the gnu and pax formats. TarInfo._frombuf() now keeps the decoding error of a text field and stores the field decoded with "surrogateescape" in the meantime. The error is forgotten when the field is replaced. Otherwise it is raised once the member has been read, as before: before any later error and without skipping the member. All headers read for the member are checked, so a subclass whose _proc_member() returns a new object still gets the error. The fields of GNU longname, longlink and pax headers themselves are not used and are no longer checked. Error handlers that do not raise give the same results as before.
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.
With
errors="strict", tarfile could not read an archive whose ustar name, linkname, uname or gname field is cut in the middle of a multibyte character, even when a GNU longname/longlink header or a pax header (extended or global) replaces that field. tarfile writes such fields itself withGNU_FORMATfor paths longer than 100 bytes, and so do GNU tar and bsdtar.TarInfo._frombuf()now keeps the decoding error of a text field and stores the field decoded withsurrogateescapein the meantime. The error is dropped when the field is replaced. OtherwiseTarInfo.frombuf()andTarInfo.fromtarfile()raise the original exception as before: before any later error, and without skipping the member. All headers read for a member are checked, so a_proc_member()override that returns a new object cannot leak unchecked values.The fields of GNU longname/longlink and pax headers themselves are never used and are no longer checked. Error handlers that do not raise give the same results as before.
Note that the private
_frombuf()no longer raises the decoding error of a text field thatsurrogateescapecan decode, so overriding it to return a new object, or calling it directly, skips the check.Tests cover GNU longnames and longlinks, pax-replaced ustar fields (including a global
path,GNU.sparse.nameand a ustar prefix), fields that are not replaced, the order of errors, reading again after an error, and subclasses.I used an AI assistant to explore the code and draft the tests. I reviewed all changes and tested them on Linux, macOS and Windows.