Skip to content

[3.13] gh-161705: Prevent shadowing stdlib in gzip/tarfile/zipfile CLI (#161706) (#161719) - #161726

Open
vstinner wants to merge 2 commits into
python:3.13from
vstinner:sys_path0_13
Open

vstinner wants to merge 2 commits into
python:3.13from
vstinner:sys_path0_13

Conversation

@vstinner

Copy link
Copy Markdown
Member

gh-161705: Prevent shadowing stdlib in gzip/tarfile/zipfile CLI (#161706)

Remove sys.path[0] in gzip, tarfile and zipfile command line interface to prevent shadowing standard library modules from extracted files.

  • Add sys._path0 variable.
  • pymain_sys_path_add_path0() sets sys._path0.
  • Add runpy._remove_sys_path0().
  • gzip, tarfile and zipfile main functions now call _remove_sys_path0() to prevent shadowing stdlib modules from extracted files.

(cherry picked from commit e891a91)

(cherry picked from commit 8aa5d65)

…ile CLI (python#161706) (python#161719)

pythongh-161705: Prevent shadowing stdlib in gzip/tarfile/zipfile CLI (python#161706)

Remove sys.path[0] in gzip, tarfile and zipfile command line
interface to prevent shadowing standard library modules from
extracted files.

* Add sys._path0 variable.
* pymain_sys_path_add_path0() sets sys._path0.
* Add runpy._remove_sys_path0().
* gzip, tarfile and zipfile main functions now call
  _remove_sys_path0() to prevent shadowing stdlib modules from
  extracted files.

(cherry picked from commit e891a91)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
(cherry picked from commit 8aa5d65)
@vstinner

Copy link
Copy Markdown
Member Author

CIFuzz / cpython3 (memory):

INFO: 3184 files found in /github/workspace/cifuzz-corpus/fuzz_struct_unpack
UnicodeEncodeError: 'ascii' codec can't encode character '\udcce' in position 0: ordinal not in range(128)

@StanFromIreland: Do you know the status of CIFuzz in the 3.13 branch? Is it still used/relevant? The code looks outdated, I suppose that these errors can just be ignored. Maybe we should even disable these CI in the 3.13 branch?

According to Modules/_xxtestfuzz/fuzzer.c, fuzz_struct_unpack() calls struct.unpack(). I downloaded the artifact file: it contains two bytes, 0xce and 0x00. On Python 3.13, I get:

$ ./python
>>> struct.unpack(b'\xce\x00', b'')
UnicodeEncodeError: 'ascii' codec can't encode character '\udcce' in position 0: ordinal not in range(128)

In the main branch, all ValueError are ignored (UnicodeEncodeError is a subclass of ValueError):

    /* Ignore any ValueError, these are triggered by non-ASCII format. */
    if (unpacked == NULL && PyErr_ExceptionMatches(PyExc_ValueError)) {
        PyErr_Clear();
    }

So I suppose that Modules/_xxtestfuzz/fuzzer.c is outdated in the 3.13 branch which no only accepts bug fixes.

@StanFromIreland

Copy link
Copy Markdown
Member

I need to discuss with the fuzzer team, but as I've proposed before, I think we should rip it out for branches that aren't main. CC @sethmlarson

@vstinner

Copy link
Copy Markdown
Member Author

I need to discuss with the fuzzer team, but as I've proposed before, I think we should rip it out for branches that aren't main. CC @sethmlarson

I would be fine with that.

@vstinner

Copy link
Copy Markdown
Member Author

I need to discuss with the fuzzer team, but as I've proposed before, I think we should rip it out for branches that aren't main. CC @sethmlarson

CIFuzz has been removed from the 3.13 branch by commit 5a869d5. So I updated the PR branch to retrieve this change.

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

3 participants