Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Use CompressionMethod.Stored and flush the ZipOutputStream after each entity was added leads Zip corrupted in SharpZipLib 1.4.2

Đang mở
#834 9 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với cách xử lý ZipOutputStream và ZipEntry được thể hiện trong báo cáo, tập trung vào việc đóng entry bất đồng bộ và FlushAsync khi sử dụng CompressionMethod.Stored. Tái hiện chuỗi này với nhiều tệp, sau đó xác minh rằng việc flush sau mỗi entity được thêm vào vẫn tạo ra một archive hợp lệ chứa mọi tệp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug zip
Describe the bug

I found a bug that if I set CompressionMethod = CompressionMethod.Stored in the entry and flush the ZipOutputStream, the output zip is corrupted and only the first file exists in the zip file.

using (Stream NewZipStream = File.OpenWrite(Path.GetRandomFileName()))
using (ZipOutputStream ZipStream = new ZipOutputStream(NewZipStream , StringCodec.FromEncoding(Encoding.UTF8)))
{
    ZipStream.SetLevel(0);
    ZipStream.UseZip64 = UseZip64.Dynamic;
    ZipStream.IsStreamOwner = false;

    foreach (string FilePath in Directory.EnumerateFiles("<Your folder that has multiple files>"))
    {
          using (Stream FileStream = File.OpenRead(FilePath))
          {
              ZipEntry NewEntry = new ZipEntry(File.Name)
              {
                  DateTime = DateTime.Now,
                  CompressionMethod = CompressionMethod.Stored,
                  Size = FileStream.Length
              };
          
              await ZipStream.PutNextEntryAsync(NewEntry, CancelToken);
              await FileStream.CopyToAsync(ZipStream);
              await ZipStream.CloseEntryAsync(CancelToken);
          }

          await ZipStream.FlushAsync(CancelToken);
    }
}
Reproduction Code

No response

Steps to reproduce
  1. Use ZipOutputStream
  2. Set CompressionMethod to CompressionMethod.Stored on ZipEntry
  3. Add multiple files/folders into ZipOutputStream
  4. Flush the ZipOutputStream once each entity was added
  5. Found the zip file is corrupted
Expected behavior

Zip is not corrupted

Operating System

Windows

Framework Version

.NET 7

Tags

ZIP

Additional context

No response

Ngôn ngữ chính
C#
Star
3.9k
Fork
1k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của icsharpcode/SharpZipLib

Tất cả issue của icsharpcode/SharpZipLib

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.