You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
expose the offset of a zipfile from the start of the file as a public API #84481
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=Noneclosed_at=Nonecreated_at=<Date2020-04-16.13:59:27.010>labels= ['type-feature', 'library', '3.9']
title='zipfile module: new feature (two lines of code), useful for test, security and forensics'updated_at=<Date2020-04-18.14:35:44.170>user='https://github.com/massimosala'
Tag "Components": I am not sure "Library (Lib)" is the correct one. If it isn't, please fix.
I use python to check zip files against malware.
In these files the are binary blobs outside the ZIP archive.
The malware payload isn't inside the ZIP file structure.
Example: a file "openme.zip" with this content :
[blob from offset 0 to offset 5678]
[ZIP archive from offset 5679 to end of file]
zipfile already handles this, finding the ZIP structure inside the file.
My change is just to add a new public property, to expose an internal variable: the file offset of the ZIP structure.
I know, I am after the code freeze of Python 2.7.18.
But the change is really trivial, see the diff.
I hope you can approve this patch for all the Python versions, also for 2.7, to have consistency. For 2.7 this is the last call.
changed the title [-]zipfile module: new feature (two lines of code)[/-][+]zipfile module: new feature (two lines of code), useful for test, security and forensics[/+]on Apr 16, 2020
changed the title [-]zipfile module: new feature (two lines of code)[/-][+]zipfile module: new feature (two lines of code), useful for test, security and forensics[/+]on Apr 16, 2020
This is a new feature and cannot be added to older versions which are in feature-freeze.
Adding the feature to (say) Python 2.7.18 would be inconsistent, because it wouldn't exist in 2.7.0 through .17. Likewise for all the other versions before 3.9.
Personally, this sounds like a nice feature to have, and your use-case sounds convincing to me.
Every software "ecosystem" has its guidelines and I am a newbie about
python development.
Mmh I see your concerns. I agree about your deletions of all py 3 versions
before the latest 3.9.
About Py 2, I remark these facts:
there are a lot of forensics tools still written for py 2;
python 2.7.18 will be forever the last python 2 and I think is it fine to
end-users to have zipfile with this feature both in py 2.7 and py 3.9;
in the code there isn't any new routine to test: the change is just to
expose one internal variable.
I agree my request is an exception but I think you have to agree this
situation is exceptional.
IMHO rules must exist to help us and I think this request doesn't carry any
burden.
I ask you please
to reconsider my request
anyway, to put me in contact with zipfile mainteners, I don't know how to
reach them but I want to hear them about this.
Many thanks, Massimo
danifus commented on Apr 18, 2020
danifusmannequin
Mannequin
More actions
Could something similar be achieved by looking for the earliest file header offset?
to see if there were any sections inside the archive which were not referenced from the central directory. Not sure if zip files with arbitrary bytes inside the archive would be valid everywhere, but I think they are using zipfile.
You can also have zipped content inside an archive which has a valid fileheader but no reference from the central directory. Those entries are discoverable by implementations which process content serially from the start of the file but not implementations which rely on the central directory.
Would you accept a PR removing the executable bit? (I don't know if Fedora is the only distribution mangling the shebangs, but I imagine this can unexpectedly hit other downstream packagers).
Activity
massimosala commentedon Apr 16, 2020
module zipfile
Tag "Components": I am not sure "Library (Lib)" is the correct one. If it isn't, please fix.
I use python to check zip files against malware.
In these files the are binary blobs outside the ZIP archive.
The malware payload isn't inside the ZIP file structure.
Example: a file "openme.zip" with this content :
[blob from offset 0 to offset 5678]
[ZIP archive from offset 5679 to end of file]
zipfile already handles this, finding the ZIP structure inside the file.
My change is just to add a new public property, to expose an internal variable: the file offset of the ZIP structure.
I know, I am after the code freeze of Python 2.7.18.
But the change is really trivial, see the diff.
I hope you can approve this patch for all the Python versions, also for 2.7, to have consistency. For 2.7 this is the last call.
[-]zipfile module: new feature (two lines of code)[/-][+]zipfile module: new feature (two lines of code), useful for test, security and forensics[/+][-]zipfile module: new feature (two lines of code)[/-][+]zipfile module: new feature (two lines of code), useful for test, security and forensics[/+]stevendaprano commentedon Apr 16, 2020
This is a new feature and cannot be added to older versions which are in feature-freeze.
Adding the feature to (say) Python 2.7.18 would be inconsistent, because it wouldn't exist in 2.7.0 through .17. Likewise for all the other versions before 3.9.
Personally, this sounds like a nice feature to have, and your use-case sounds convincing to me.
massimosala commentedon Apr 17, 2020
Hi Steven
Every software "ecosystem" has its guidelines and I am a newbie about
python development.
Mmh I see your concerns. I agree about your deletions of all py 3 versions
before the latest 3.9.
About Py 2, I remark these facts:
end-users to have zipfile with this feature both in py 2.7 and py 3.9;
expose one internal variable.
I agree my request is an exception but I think you have to agree this
situation is exceptional.
IMHO rules must exist to help us and I think this request doesn't carry any
burden.
I ask you please
reach them but I want to hear them about this.
Many thanks, Massimo
danifus commentedon Apr 18, 2020
Could something similar be achieved by looking for the earliest file header offset?
You could also adapt this using
to see if there were any sections inside the archive which were not referenced from the central directory. Not sure if zip files with arbitrary bytes inside the archive would be valid everywhere, but I think they are using zipfile.
You can also have zipped content inside an archive which has a valid fileheader but no reference from the central directory. Those entries are discoverable by implementations which process content serially from the start of the file but not implementations which rely on the central directory.
38 remaining items
hroncok commentedon Apr 14, 2025
Do the test files need to be executable?
vstinner commentedon Apr 14, 2025
Python and Python test suite don't need the script to be executable, but you can run these 2 test scripts.
Example:
befeleme commentedon Apr 14, 2025
Would you accept a PR removing the executable bit? (I don't know if Fedora is the only distribution mangling the shebangs, but I imagine this can unexpectedly hit other downstream packagers).
hroncok commentedon Apr 14, 2025
Turns out
test_execute_zip64and other similar tests need that.Revert "pythongh-84481: Make ZipFile.data_offset more robust (python#…
Revert "pythongh-84481: Add ZipFile.data_offset attribute (python#132165
gh-136170: Revert adding `ZipFile.data_offset` (GH-136950)
pythongh-136170: Revert adding `ZipFile.data_offset` (pythonGH-136950)
gpshead commentedon Jul 22, 2025
reopening as we pulled
.data_offsetfrom 3.14 (see PR and issues).[3.14] gh-136170: Revert adding `ZipFile.data_offset` (GH-136950) (#1…
pythongh-136170: Revert adding `ZipFile.data_offset` (pythonGH-136950)
pythongh-136170: Revert adding `ZipFile.data_offset` (pythonGH-136950)
[3.14] pythongh-136170: Revert adding `ZipFile.data_offset` (pythonGH…