Skip to content

Conversation

@Zheaoli
Copy link
Contributor

@Zheaoli Zheaoli commented Nov 1, 2024

@Zheaoli
Copy link
Contributor Author

Zheaoli commented Nov 4, 2024

@serhiy-storchaka PTAL when you got time(

@Zheaoli
Copy link
Contributor Author

Zheaoli commented Nov 22, 2024

@serhiy-storchaka ping (

@serhiy-storchaka serhiy-storchaka self-requested a review November 22, 2024 14:30
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some refactoring, but except a struct.error the new code looks equivalent to the old one. Could you please point what was changed in the behavior?

Lib/tarfile.py Outdated
if self.__read(2) != b"\037\213":
raise ReadError("not a gzip file")
if self.__read(1) != b"\010":
(method, flag, _) = struct.unpack("<BBIxx", self.__read(8))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if it read less than 8 bytes?

Why use I and then ignore the result?

xlen = ord(self.__read(1)) + 256 * ord(self.__read(1))
self.read(xlen)
extra_len, = struct.unpack("<H", self.__read(2))
self.__read(extra_len)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the only relevant change is in this line.

@Zheaoli
Copy link
Contributor Author

Zheaoli commented Nov 26, 2024

Hi @serhiy-storchaka Thanks for the review!

  1. You are right, the core change is self.__read(extra_len) so we can skip the header correctly
  2. I prefer use the struct.pack instead of cast the binary offset manually. I think this will make the code more readable and keep same style with gzip.py

@Zheaoli
Copy link
Contributor Author

Zheaoli commented May 22, 2025

@serhiy-storchaka PTAL when you get time

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tarfiles can't open tgz files with gzip features like FEXTRA & FCOMMENT when mode='r|*'

3 participants