Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tarfile.open(fileobj=f) and bad metadata of the first file within the archive #45872

Closed
GeorgeNotaras mannequin opened this issue Nov 30, 2007 · 3 comments
Closed

tarfile.open(fileobj=f) and bad metadata of the first file within the archive #45872

GeorgeNotaras mannequin opened this issue Nov 30, 2007 · 3 comments
Assignees
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@GeorgeNotaras
Copy link
Mannequin

GeorgeNotaras mannequin commented Nov 30, 2007

BPO 1531
Nosy @gustaebel

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/gustaebel'
closed_at = <Date 2007-12-01.21:15:56.832>
created_at = <Date 2007-11-30.23:00:06.371>
labels = ['extension-modules', 'type-bug']
title = 'tarfile.open(fileobj=f) and bad metadata of the first file within the archive'
updated_at = <Date 2007-12-02.01:39:45.729>
user = 'https://bugs.python.org/GeorgeNotaras'

bugs.python.org fields:

activity = <Date 2007-12-02.01:39:45.729>
actor = 'GeorgeNotaras'
assignee = 'lars.gustaebel'
closed = True
closed_date = <Date 2007-12-01.21:15:56.832>
closer = 'lars.gustaebel'
components = ['Extension Modules']
creation = <Date 2007-11-30.23:00:06.371>
creator = 'GeorgeNotaras'
dependencies = []
files = []
hgrepos = []
issue_num = 1531
keywords = []
message_count = 3.0
messages = ['58026', '58069', '58076']
nosy_count = 2.0
nosy_names = ['lars.gustaebel', 'GeorgeNotaras']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue1531'
versions = ['Python 2.5']

@GeorgeNotaras
Copy link
Mannequin Author

GeorgeNotaras mannequin commented Nov 30, 2007

Assume the following situation:

  • a healthy and uncompressed tar file: a.tar
  • the metadata of the 1st and second files within the archive start at
    positions 0 and 756 (realistic example values)

I partially damage 200 bytes of metadata (byte range 0-500) of the first
archived file:

f = open("a.tar", "rb+")
f.seek(100)
f.write("0"*200)

Now, I seek to the start of the 2nd archived file's metadata:

f.seek(756)

And I try to open the tar archive using tarfile.open() passing the
previous fileobject to it.

import tarfile
f_tar = tarfile.open(fileobj=f)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tarfile.py", line 1143, in open
    raise ReadError("file could not be opened successfully")
tarfile.ReadError: file could not be opened successfully

Wouldn't the expected behaviour be to successfully open the tar archive
at offset 756?

It seems that tarfile.open(fileobj=f) seeks to position 0 of the
fileobject f, fails to read the 1st archived file's metadata and throws
an exception.

@GeorgeNotaras GeorgeNotaras mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Nov 30, 2007
@gustaebel gustaebel mannequin self-assigned this Dec 1, 2007
@gustaebel
Copy link
Mannequin

gustaebel mannequin commented Dec 1, 2007

I fixed this in the trunk (r59260) and release25-maint branch (r59261).
Thanks for the report. If you cannot wait for the next release, I
recommend you use mode "r|" as a workaround.

BTW, 756 is absolutely no realistic example value for the position of
the second member. A header block must start on a 512-byte boundary.

@gustaebel gustaebel mannequin closed this as completed Dec 1, 2007
@GeorgeNotaras
Copy link
Mannequin Author

GeorgeNotaras mannequin commented Dec 2, 2007

Thanks for the quick fix and the workaround.

You are right about position 756. I hadn't spent enough time studying
the ''ustar'' format.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

0 participants