Skip to content

Fixed #168. Rubyzip changed default behavior.#170

Merged
satoryu merged 2 commits into
ruby-docx:masterfrom
abartov:master
May 31, 2026
Merged

Fixed #168. Rubyzip changed default behavior.#170
satoryu merged 2 commits into
ruby-docx:masterfrom
abartov:master

Conversation

@abartov
Copy link
Copy Markdown
Contributor

@abartov abartov commented Dec 6, 2025

The issue with file saving was that Rubyzip 3.x now saves ZIP64 by default. This is unexpected and unsupported by many tools, and best not to enable by default in docx.

I'd appreciate it if the maintainers merge this and release a new gem.

Copilot AI review requested due to automatic review settings December 6, 2025 02:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #168 by disabling ZIP64 support in rubyzip to fix compatibility issues with file saving. Rubyzip 3.x changed its default behavior to enable ZIP64 by default, which causes problems with tools like pandoc that don't support ZIP64 for small files. The fix adds a global configuration setting to disable ZIP64 support.

  • Adds global configuration Zip.write_zip64_support = false to disable ZIP64
  • Includes explanatory comments about rubyzip 3.x default behavior change
  • Aims to restore compatibility with readers that don't support ZIP64

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/docx/document.rb Outdated
Comment on lines +8 to +11
# Disable ZIP64 support to maintain compatibility with version 0.9.1 and
# ensure compatibility with all readers. Rubyzip 3.x enables ZIP64 by default,
# but many readers (including pandoc) don't support it for small files.
Zip.write_zip64_support = false
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

Setting global Zip configuration in a library gem is problematic. This modifies global state for all code using rubyzip in the consuming application, potentially breaking other functionality that may need ZIP64 support.

Consider investigating per-operation ZIP64 configuration instead of global configuration. If rubyzip 3.x doesn't support per-operation configuration, consider:

  1. Documenting this global configuration change prominently in README and CHANGELOG
  2. Providing a configuration option that allows users to opt-in/out of this behavior
  3. Only setting this configuration in the save and stream methods and restoring it afterwards

This approach would minimize side effects on other code while achieving the same compatibility goal.

Copilot uses AI. Check for mistakes.
Comment thread lib/docx/document.rb Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
maatinito added a commit to maatinito/inspecteur-mes-demarches that referenced this pull request Feb 11, 2026
docx 0.10.0 autorise rubyzip 3.x qui active ZIP64 par défaut.
LibreOffice ne peut pas ouvrir les docx en format ZIP64, causant
l'échec silencieux de la conversion PDF ("source file could not
be loaded"). Verrouillage à docx ~> 0.8.0 (rubyzip 2.x).

Ref: ruby-docx/docx#170

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@abartov
Copy link
Copy Markdown
Contributor Author

abartov commented May 25, 2026

@satoryu - could I ask for some attention to this PR? It fixes something people still keep struggling with.

@satoryu satoryu merged commit 16e42c2 into ruby-docx:master May 31, 2026
5 checks passed
satoryu added a commit that referenced this pull request May 31, 2026
PR #170 fixed #168 by setting Zip.write_zip64_support = false at the
top level when docx is required. That mutates global rubyzip state for
the whole host application, which can break other code that relies on
ZIP64 (flagged by Copilot review on #170).

Instead, disable ZIP64 only while writing in #save / #stream via a
with_zip64_disabled helper that restores the previous global value in
an ensure block, so other rubyzip users are unaffected. Adds regression
specs asserting the setting is not leaked after saving/streaming, and a
CHANGELOG entry.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
satoryu added a commit that referenced this pull request May 31, 2026
Scope ZIP64 disabling to save/stream (follow-up to #170)
@satoryu
Copy link
Copy Markdown
Member

satoryu commented May 31, 2026

Hi @abartov, sorry for the delayed response on this — and thank you for sending the PR! 🙏

I've merged your fix and just released it as part of the latest gem version, v0.10.1. It's now available on RubyGems. For more details, please see the release notes: https://github.com/ruby-docx/docx/releases/tag/v0.10.1

As a small follow-up, I scoped the Zip.write_zip64_support = false change to only apply during save/stream (restoring the previous value afterwards) so it doesn't mutate global rubyzip state for the whole host application — see #172 for details.

Thanks again for catching and fixing this!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants