Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Frequent file curruption using Encryption

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #19873 |

    We’re seeing messages of this type:

    “An error occurred while creating the response file: The zip end header signature could not be found in the zip file. Zip file C:\Documents and Settings\Jim\My Documents\Myzipfile.zip”

    at a high rate of frequency – probably one out of every 250-300 zip file saves becomes corrupted with bad header signature problem. Is there any known issues with using encryption in the Zip files that I should be aware of (the files are saved using the badic samples found in the help files).

    Is the best way to guard against this to write out the zip file then try and read it back in to test if it’s okay, or is there some other methodolgy for protecting against the corruption?

    Imported from legacy forums. Posted by Shmuel (had 4309 views)

    Xceed Support
    Member
    Post count: 5658

    Looking through our inquiry Database, this is the first report we get related to this kind of issue. Even if the code your are using is simple, could you provide a snippet of it?

    Imported from legacy forums. Posted by CharlesB (had 291 views)

    User (Old forums)
    Member
    Post count: 23064

    We call it like something like this:

    private ZipArchive myArchive;
    void main()
    {
    CreateResponseFile(); // Initializes the zip archive
    Backup();

    byte[] b = “some bytes”;
    SaveCurrentFiles(b);

    }

    public void CreateResponseFile( )
    {
    myArchive = OpenZipArchive(Path.Combine(inProgressDirectoryPath, myFileName), thePassword);
    }

    private static ZipArchive OpenZipArchive(string fullName, string password)
    {
    #region Parameter Validation
    #endregion

    DiskFile diskFile = new DiskFile( fullName );
    ZipArchive zipArchive = new ZipArchive(diskFile);
    zipArchive.DefaultCompressionLevel = CompressionLevel.Highest;
    zipArchive.DefaultCompressionMethod = CompressionMethod.Deflated64;
    zipArchive.DefaultDecryptionPassword = password;
    zipArchive.DefaultEncryptionMethod = EncryptionMethod.WinZipAes;
    zipArchive.DefaultEncryptionPassword = password;
    zipArchive.DefaultEncryptionStrength = 256;
    return zipArchive;
    }

    public void Backup( )
    {
    try
    {
    String suffix = String.Format( CultureInfo.InvariantCulture, @”.backup-{0}”, DateTime.Now.ToString( @”ddHHmmss”, CultureInfo.InvariantCulture ) );

    File.Copy( myArchive.ZipFile.FullName, myArchive.ZipFile.FullName + suffix, true );

    }
    catch( Exception ex )
    {
    throw new FileSystemException( Resources.AnErrorOccurredWhileBackingUpTheCurrentFile, ex );
    }
    }

    public void SaveCurrentFiles(byte[] theBytes)
    {
    using (Stream strm = OpenWrite (“myFile.doc”))
    {
    strm.Write (theBytes, 0, theBytes.Length);
    }

    }

    public Stream OpenWrite( string name )
    {
    #region Parameter Validation
    #endregion

    Stream stream;

    try
    {
    AbstractFile theFile;

    theFile = responseArchive.GetFile( name );

    if( false == theFile.Exists )
    {
    theFile = responseArchive.CreateFile( name, true );
    }

    stream = theFile.OpenWrite( true );
    }
    catch( Exception ex )
    {
    throw new FileSystemException();
    }

    return stream;
    }

    Imported from legacy forums. Posted by Shmuel (had 458 views)

    Xceed Support
    Member
    Post count: 5658

    After reviewing your code, there does not seem to be anything that should trigger this kind of exception.

    Are you compressing large files and about how many of them? Do you create the archives from scratch or update archives created by another application? If not, is it possible to create a repro app and provide some small files that reproduce the problem often enough.

    Also, instead of using File.Copy(…), you can use:

    DiskFile targetFile = new DiskFile(myArchive.ZipFile.FullName + suffix);
    myArchive.HostFile.CopyTo(targetFile, true );

    Imported from legacy forums. Posted by CharlesB (had 324 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    There is a tool called Advanced Zip Repair. I have used it to repair many corrupt Zip files on my damaged disks successfully. Its homepage is http://www.datanumen.com/azr/

    Alan

    Imported from legacy forums. Posted by zxr (had 5069 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.