jaime-olivares / zipstorer

A Pure C# Class to Store Files in Zip
MIT License
183 stars 63 forks source link

Invalid Zip64 extended information record format #46

Open IEVin opened 2 years ago

IEVin commented 2 years ago

Hi! Thanks for awesome tool to work with zip! Unfortunately i ran into a problem when reading the zip64 file.

According with zip format specification fields in zip64 extended information record MUST only appear if the corresponding Local or Central directory record field is set to 0xFFFF or 0xFFFFFFFF

This issue may be fixed by change // ZIP64 Information block in ReadExtraInfo function to this:

if (extraId == 0x0001) // ZIP64 Information
{
    int extraOffset = 4;
    if (_zfe.FileSize == 0xFFFFFFFF)
    {
        _zfe.FileSize = BitConverter.ToInt64(buffer, pos + extraOffset);
        extraOffset += 8;
    }
    if (_zfe.CompressedSize == 0xFFFFFFFF)
    {
        _zfe.CompressedSize = BitConverter.ToInt64(buffer, pos + extraOffset);
        extraOffset += 8;
    }
    if (_zfe.HeaderOffset == 0xFFFFFFFF)
    {
        _zfe.HeaderOffset = BitConverter.ToInt64(buffer, pos + extraOffset);
    }
}

And calculate zfe.FileOffset after invocation ReadExtraInfo.

But CreateExtraInfo should be rewrited to.