### Vulnerability Overview - **Vulnerability ID**: gh-141707 - **Description**: The normalization of `TarInfo` `DIRTYPE` is skipped when processing GNU long filenames. Specifically, when a filename ends with `/`, the `AREGTYPE` header is converted to a `DIRTYPE` header; however, this conversion is skipped during the processing of GNU long filenames. - **Impact**: This may cause files of directory type to be incorrectly identified as regular files when processing tar archives containing GNU long filenames. ### Scope of Impact - **Affected Module**: `Lib/tarfile.py` - **Affected Functions**: `_frombuf`, `_fromtarfile`, `_proc_pax` - **Specific Scenario**: When parsing a tar file containing GNU long filenames, if the filename ends with `/`, the `AREGTYPE` header is not correctly converted to a `DIRTYPE` header. ### Remediation - **Fixed File**: `Lib/tarfile.py` - **Fix Details**: - In the `_frombuf` function, a check for the `dircheck` parameter was added to ensure that the `AREGTYPE` header is converted to a `DIRTYPE` header when `dircheck` is `True`. - Similarly, a check for the `dircheck` parameter was added in the `_fromtarfile` function. - A check for the `dircheck` parameter was also added in the `_proc_pax` function. ### POC Code ```python def test_longname_file_not_directory(self): # Test reading a longname file and ensure it is not handled as a directory # Issue #141707 buf = io.BytesIO() with tarfile.open(mode='w', fileobj=buf, format=self.format) as tar: ti = tarfile.TarInfo() ti.type = tarfile.AREGTYPE ti.name = ('a' * 99) + '/' + ('b' * 3) tar.addfile(ti) buf.seek(0) with tarfile.open(mode='r', fileobj=buf) as tar: actual = {t.name: t.type for t in tar.getmembers()} self.assertEqual(expected, actual) ``` ### Summary This vulnerability involves the failure to correctly convert the `AREGTYPE` header to a `DIRTYPE` header when processing GNU long filenames, resulting in directory-type files being incorrectly identified. The remediation ensures type conversion occurs in appropriate scenarios by adding checks for the `dircheck` parameter in the relevant functions.