[GH-ISSUE #228] Turn on ZIP64 support #184

Closed
opened 2026-05-05 11:51:13 -06:00 by gitea-mirror · 10 comments
Owner

Originally created by @evanmiller on GitHub (May 15, 2019).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/228

Originally assigned to: @jmcnamara on GitHub.

I get an error when creating an especially large XLSX file (see #227). The underlying error is ZIP_BADZIPFILE, triggered at

https://github.com/jmcnamara/libxlsxwriter/blob/master/third_party/minizip/zip.c#L1731

I believe this can be fixed by changing the last argument to zipOpenNewFileInZip4_64 be 1 instead of 0 here:

https://github.com/jmcnamara/libxlsxwriter/blob/master/src/packager.c#L1063-L1069

I.e. that turns on Zip64 support which permits 4GB+ uncompressed file sizes to be written.

Originally created by @evanmiller on GitHub (May 15, 2019). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/228 Originally assigned to: @jmcnamara on GitHub. I get an error when creating an especially large XLSX file (see #227). The underlying error is `ZIP_BADZIPFILE`, triggered at https://github.com/jmcnamara/libxlsxwriter/blob/master/third_party/minizip/zip.c#L1731 I believe this can be fixed by changing the last argument to `zipOpenNewFileInZip4_64` be `1` instead of `0` here: https://github.com/jmcnamara/libxlsxwriter/blob/master/src/packager.c#L1063-L1069 I.e. that turns on Zip64 support which permits 4GB+ uncompressed file sizes to be written.
gitea-mirror 2026-05-05 11:51:13 -06:00
Author
Owner

@jmcnamara commented on GitHub (May 15, 2019):

Agreed. That could/should be added. It is supported in the Python version of the library: https://xlsxwriter.readthedocs.io/workbook.html#workbook-use-zip64

<!-- gh-comment-id:492637319 --> @jmcnamara commented on GitHub (May 15, 2019): Agreed. That could/should be added. It is supported in the Python version of the library: https://xlsxwriter.readthedocs.io/workbook.html#workbook-use-zip64
Author
Owner

@jmcnamara commented on GitHub (Jun 7, 2019):

I've added this to master.

From the docs:

/**
 * @brief Allow ZIP64 extensions when creating the xlsx file zip container.
 *
 * @param workbook Pointer to a lxw_workbook instance.
 *
 * Use ZIP64 extensions when writing the xlsx file zip container to allow
 * files greater than 4 GB.
 *
 * @code
 *     workbook_use_zip64(workbook);
 * @endcode
 */

And from a sample file generated with the ZIP64 extensions:

$ zipdetails zip64.xlsx

0000 LOCAL HEADER #1       04034B50
0004 Extract Zip Spec      2D '4.5'
0005 Extract OS            00 'MS-DOS'
0006 General Purpose Flag  0000
     [Bits 1-2]            0 'Normal Compression'
0008 Compression Method    0008 'Deflated'
000A Last Mod Time         00210000 'Tue Jan  1 00:00:00 1980'
000E CRC                   3A495D61
0012 Compressed Length     0000014F
0016 Uncompressed Length   0000048F
001A Filename Length       0013
001C Extra Length          0014
001E Filename              '[Content_Types].xml'
0031 Extra ID #0001        0001 'ZIP64'
0033   Length              0010
0035 PAYLOAD
<!-- gh-comment-id:500069335 --> @jmcnamara commented on GitHub (Jun 7, 2019): I've added this to master. From the docs: ```doxygen /** * @brief Allow ZIP64 extensions when creating the xlsx file zip container. * * @param workbook Pointer to a lxw_workbook instance. * * Use ZIP64 extensions when writing the xlsx file zip container to allow * files greater than 4 GB. * * @code * workbook_use_zip64(workbook); * @endcode */ ``` And from a sample file generated with the ZIP64 extensions: ``` $ zipdetails zip64.xlsx 0000 LOCAL HEADER #1 04034B50 0004 Extract Zip Spec 2D '4.5' 0005 Extract OS 00 'MS-DOS' 0006 General Purpose Flag 0000 [Bits 1-2] 0 'Normal Compression' 0008 Compression Method 0008 'Deflated' 000A Last Mod Time 00210000 'Tue Jan 1 00:00:00 1980' 000E CRC 3A495D61 0012 Compressed Length 0000014F 0016 Uncompressed Length 0000048F 001A Filename Length 0013 001C Extra Length 0014 001E Filename '[Content_Types].xml' 0031 Extra ID #0001 0001 'ZIP64' 0033 Length 0010 0035 PAYLOAD ```
Author
Owner

@evanmiller commented on GitHub (Jun 8, 2019):

Would use_zip64 make more sense as a field in lxw_workbook_options? That would seem to provide a more consistent API than a one-off function like this.

<!-- gh-comment-id:500115997 --> @evanmiller commented on GitHub (Jun 8, 2019): Would `use_zip64` make more sense as a field in `lxw_workbook_options`? That would seem to provide a more consistent API than a one-off function like this.
Author
Owner

@jmcnamara commented on GitHub (Jun 8, 2019):

Would use_zip64 make more sense as a field in lxw_workbook_options

That was my first thought but the Python version uses a function/method (use_zip64()) so I went with that.

The lxw_workbook_options are mainly for options that need to be defined at construction time or are very common. The zip64 option isn't in either of those categories and doesn't seem to be very commonly required. You are only the second person to request or mention it across the Perl/Python/C versions. So I'll leave it as a function for now, but I'll think about it up until the release.

<!-- gh-comment-id:500122570 --> @jmcnamara commented on GitHub (Jun 8, 2019): > Would `use_zip64` make more sense as a field in `lxw_workbook_options` That was my first thought but the Python version uses a function/method ([use_zip64()](https://xlsxwriter.readthedocs.io/workbook.html#workbook-use-zip64)) so I went with that. The `lxw_workbook_options` are mainly for options that need to be defined at construction time or are very common. The zip64 option isn't in either of those categories and doesn't seem to be very commonly required. You are only the second person to request or mention it across the Perl/Python/C versions. So I'll leave it as a function for now, but I'll think about it up until the release.
Author
Owner

@evanmiller commented on GitHub (Jun 8, 2019):

Well, I have been using libxlsxwriter in shipping code for a number of years, and Zip64 wasn't something I knew I needed until recently. It took some fairly deep debugging to figure out that its absence was triggering write failures. If it had been an advertised option sooner, I certainly would have enabled it. So I suspect that many clients of libxlsxwriter will choose to enable Zip64 once they are made aware of it.

One advantage of using an option instead of a function is that in the future, you will be able to make Zip64 the default (opt-out) without changing the API. The new API is opt-in only.

<!-- gh-comment-id:500123373 --> @evanmiller commented on GitHub (Jun 8, 2019): Well, I have been using libxlsxwriter in shipping code for a number of years, and Zip64 wasn't something I knew I needed until recently. It took some fairly deep debugging to figure out that its absence was triggering write failures. If it had been an advertised option sooner, I certainly would have enabled it. So I suspect that many clients of libxlsxwriter will choose to enable Zip64 once they are made aware of it. One advantage of using an option instead of a function is that in the future, you will be able to make Zip64 the default (opt-out) without changing the API. The new API is opt-in only.
Author
Owner

@jmcnamara commented on GitHub (Jun 8, 2019):

Okay. I'm persuaded. I'll enable it in the lxw_workbook_options.

<!-- gh-comment-id:500125414 --> @jmcnamara commented on GitHub (Jun 8, 2019): Okay. I'm persuaded. I'll enable it in the `lxw_workbook_options`.
Author
Owner

@jmcnamara commented on GitHub (Jun 8, 2019):

I've refactored the use_zip64 option into the constructor. It can now be called as follows:

int main() {

    lxw_workbook_options options = {.constant_memory = LXW_FALSE,
                                    .tmpdir = NULL,
                                    .use_zip64 = LXW_TRUE};

    lxw_workbook  *workbook  = workbook_new_opt("zip64.xlsx", &options);
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    ...

When you get a chance try it out and see what you think. The docs have been updates as well.

<!-- gh-comment-id:500132569 --> @jmcnamara commented on GitHub (Jun 8, 2019): I've refactored the `use_zip64` option into the constructor. It can now be called as follows: ```C int main() { lxw_workbook_options options = {.constant_memory = LXW_FALSE, .tmpdir = NULL, .use_zip64 = LXW_TRUE}; lxw_workbook *workbook = workbook_new_opt("zip64.xlsx", &options); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); ... ``` When you get a chance try it out and see what you think. The docs have been updates as well.
Author
Owner

@jmcnamara commented on GitHub (Jun 8, 2019):

When you get a chance try it out and see what you think.

After I fix the failing test cases on Linux.

<!-- gh-comment-id:500132691 --> @jmcnamara commented on GitHub (Jun 8, 2019): > When you get a chance try it out and see what you think. After I fix the failing test cases on Linux.
Author
Owner

@jmcnamara commented on GitHub (Jun 8, 2019):

Okay. Master is fixed again.

<!-- gh-comment-id:500134604 --> @jmcnamara commented on GitHub (Jun 8, 2019): Okay. Master is fixed again.
Author
Owner

@evanmiller commented on GitHub (Jun 8, 2019):

The new code is working as expected. Thanks.

<!-- gh-comment-id:500143279 --> @evanmiller commented on GitHub (Jun 8, 2019): The new code is working as expected. Thanks.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#184
No description provided.