Writing zero length files to a ZIP causes a crash #23

Open
opened 2026-01-29 22:03:39 +00:00 by claunia · 0 comments
Owner

Originally created by @ptallett on GitHub (Dec 26, 2014).

Trying to add a zero length file to a ZIP file causes the library to crash. A crude fix is as follows:

In CBZip2OutputStream.cs

    private void MainSort()
    {
        int i, j, ss, sb;
        int[] runningOrder = new int[256];
        int[] copy = new int[256];
        bool[] bigDone = new bool[256];
        int c1, c2;
        int numQSorted;

        /*
        In the various block-sized structures, live data runs
        from 0 to last+NUM_OVERSHOOT_BYTES inclusive.  First,
        set up the overshoot area for block.
        */

        last = last == -1 ? 0 : last;       // PRT: Prevent crash on zero length files

Cheers,
Paul

Originally created by @ptallett on GitHub (Dec 26, 2014). Trying to add a zero length file to a ZIP file causes the library to crash. A crude fix is as follows: In CBZip2OutputStream.cs ``` private void MainSort() { int i, j, ss, sb; int[] runningOrder = new int[256]; int[] copy = new int[256]; bool[] bigDone = new bool[256]; int c1, c2; int numQSorted; /* In the various block-sized structures, live data runs from 0 to last+NUM_OVERSHOOT_BYTES inclusive. First, set up the overshoot area for block. */ last = last == -1 ? 0 : last; // PRT: Prevent crash on zero length files ``` Cheers, Paul
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#23