Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZipFile.TestArchive() returns true for empty file #723

Open
mochaloff opened this issue Feb 13, 2022 · 0 comments
Open

ZipFile.TestArchive() returns true for empty file #723

mochaloff opened this issue Feb 13, 2022 · 0 comments
Labels
bug zip Related to ZIP file format

Comments

@mochaloff
Copy link

mochaloff commented Feb 13, 2022

Steps to reproduce

  1. Create Empty *.txt file and rename extension to *.zip
  2. Use OpenReadStream() and TestArchive(true, TestStrategy.FindFirstError, null)

Expected behavior

The method must return false

Actual behavior

Method returns true

Version of SharpZipLib

1.3.3

Obtained from (only keep the relevant lines)

  • Package installed using NuGet

Notably, the method returns false if there is any information in the text file

My code:

public static bool IsCorrectZipFile(this IFormFile zipFile) //zipFile = emptyTxtFile.zip
{
    try
    {
        bool result;

        using (ZipFile zip = new ZipFile(zipFile.OpenReadStream()))
        {
            result = zip.TestArchive(true, TestStrategy.FindFirstError, null);
        }
        return result;
    }
    catch
    {
        return false;
    }
}
@piksel piksel changed the title .TestArchive() does not work correctly if you mask an empty text file into a zip archive ZipFile.TestArchive() returns true for empty file Feb 14, 2022
@piksel piksel added bug zip Related to ZIP file format labels Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug zip Related to ZIP file format
Projects
None yet
Development

No branches or pull requests

2 participants