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

Using Zip.sort_entries appears to change file header in place when using block with File.open #329

Closed
stadelmanma opened this issue May 18, 2017 · 2 comments
Assignees
Labels
Milestone

Comments

@stadelmanma
Copy link

I ran into this when working with docx files and after refactoring some code the test fixtures were getting modified but for the life of me I couldn't tell how. The unzipped content of the archive is unchanged however the number of bytes slightly changes (which I assume is the file ordering?). Zip::File.open.each does not modify the file in place, nor does using Zip::File.open_buffer on the raw stream.

The block below can reproduce the error.

Zip.sort_entries = true # required to process document.xml before numbering.xml
Zip::File.open('../fixtures/conditionals_template.docx') do |docx_zip|
end

For a full demonstration of the problem you can pull down my branch of Sablon here (use the zip-modify-inplace branch) and then run bundle exec rake. Ignore the failing test and afterwards you can use git status to see all of the fixtures be modified.

@leandronsp
Copy link

leandronsp commented May 19, 2017

@stadelmanma I realized the problem starts on lib/zip/entry_set.rb:71, exactly while calling @entry_set.sort. I guess the root cause resides on the way the @entry_set is being manipulated somewhere.

@hainesr hainesr self-assigned this Jun 29, 2021
@hainesr hainesr added the bug label Jun 29, 2021
@hainesr hainesr added this to the 3.0 milestone Jun 29, 2021
@hainesr
Copy link
Member

hainesr commented Jun 29, 2021

It seems ridiculous that simply opening and closing a zip file with Zip.sort_entries = true should alter that file on disk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants