Currently onedrive generates zip files that are broken to most software.


As we can see here, the solution is to use a hex editor. Since I have lots of large files, I want bash script solution...is it possible?

This is a test file freely available:


  • Is your question about how to fix the zip file or just how to extract the data from it?
    – pmqs
    Commented May 30, 2020 at 13:03
  • How to fix it @pmqs
    – Freedo
    Commented May 30, 2020 at 17:56
  • 1
    I have a small Perl script I hacked together a while back to fix these files. Let me tidy it up a bit before I post it
    – pmqs
    Commented May 30, 2020 at 18:57
  • 1
    you are the hero the internet needs @pmqs
    – Freedo
    Commented May 30, 2020 at 19:44

1 Answer 1


The issue referred to in the link in the question, Does Microsoft OneDrive export large ZIP files that are corrupt?, refers to a problem where zip files created by OneDrive larger than 4Gig have an invalid Total Number of Disks field in the ZIP64 End Central Directory Locator. The value in this field should be 1, but OneDrive (and it seems Windows send-to-zip) sets it to 0. This makes it difficult/impossible to work with these files using standard unzip utilities.

Running unzip against one of these files produces output like this

$ unzip -l  onedrive-zip-test-zeros.zip
Archive:  onedrive-zip-test-zeros.zip
warning [onedrive-zip-test-zeros.zip]:  1073742329 extra bytes at beginning or within zipfile
  (attempting to process anyway)
error [onedrive-zip-test-zeros.zip]:  start of central directory not found;
  zipfile corrupt.
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)

The link in the original question shows how to manually fix the issue with a hex file editor. Alternatively, see Fix-OneDrive-Zip for a script that will fix these OneDrive zip files. All it does is to set the value to 1 if it is incorrectly set to 0.

Usage is

fix-onedrive-zip file1.zip 

In this instance

$./fix-onedrive-zip onedrive-zip-test-zeros.zip 

Checking 'onedrive-zip-test-zeros.zip'
Updated 'onedrive-zip-test-zeros.zip'

and checking the zip file can be read

$ unzip -l onedrive-zip-test-zeros.zip 
Archive:  onedrive-zip-test-zeros.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
1073741824  2020-03-18 14:48   onedrive-zip-test-zeros/file01.dat
1073741824  2020-03-18 14:51   onedrive-zip-test-zeros/file02.dat
1073741824  2020-03-18 14:54   onedrive-zip-test-zeros/file03.dat
1073741824  2020-03-18 14:57   onedrive-zip-test-zeros/file04.dat
1073741824  2020-03-18 15:01   onedrive-zip-test-zeros/file05.dat
---------                     -------
5368709120                     5 files
  • I've tried with two zip files I had here but it says: cannot find zip at end of...
    – Freedo
    Commented May 31, 2020 at 0:50
  • is it possible i'm been affected by another bug? because i thought it was that one, but my zips i downloaded from the web inteface doesn't work, and your script says that
    – Freedo
    Commented May 31, 2020 at 1:00
  • Can you create an issue at github.com/pmqs/Fix-OneDrive-Zip/issues please? There is either an edge condition that my script doesn't handle, or there is a different issue in your zip files.
    – pmqs
    Commented May 31, 2020 at 7:00
  • Can do, but let's see if this is a fix for the original question first. Need to work through the issues that @Freedo is having with the script.
    – pmqs
    Commented May 31, 2020 at 15:55
  • 1
    Onedrive/sharepoint is a disaster! Will destroy account on the first possible oppertunity.
    – Bjorn
    Commented Feb 17, 2021 at 0:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .