Skip to content

Commit 36c8e8c

Browse files
committed
Handle empty archives (w/ size of 22 bytes)
1 parent 3d91449 commit 36c8e8c

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/cZipArchive.cls

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -805,20 +805,20 @@ Public Function OpenArchive(ArchiveFile As Variant) As Boolean
805805
pvSetError
806806
m_lCurrentFile = -1
807807
uArchiveFile = pvVfsOpen(ArchiveFile)
808-
For lIdx = 0 To MAX_END_SEEK
809-
If pvVfsSeek(uArchiveFile, -LNG_LEN_END - lIdx, FILE_END) <= 0 Then
810-
lIdx = MAX_END_SEEK + 1
811-
Exit For
812-
End If
813-
Debug.Assert VarPtr(uEndHdr.LenCom) + 2 - VarPtr(uEndHdr.Signature) = LNG_LEN_END
814-
pvVfsRead uArchiveFile, VarPtr(uEndHdr), LNG_LEN_END
815-
If uEndHdr.Signature = LNG_SIG_END And uEndHdr.LenCom = lIdx Then
816-
Exit For
817-
End If
818-
Next
819-
If lIdx > MAX_END_SEEK Then
808+
lIdx = pvVfsSeek(uArchiveFile, 0, FILE_END)
809+
If lIdx >= LNG_LEN_END Then
810+
For lIdx = 0 To LimitLong(lIdx - LNG_LEN_END, , MAX_END_SEEK)
811+
pvVfsSeek uArchiveFile, -LNG_LEN_END - lIdx, FILE_END
812+
Debug.Assert VarPtr(uEndHdr.LenCom) + 2 - VarPtr(uEndHdr.Signature) = LNG_LEN_END
813+
pvVfsRead uArchiveFile, VarPtr(uEndHdr), LNG_LEN_END
814+
If uEndHdr.Signature = LNG_SIG_END And uEndHdr.LenCom = lIdx Then
815+
lIdx = -1
816+
Exit For
817+
End If
818+
Next
819+
End If
820+
If lIdx >= 0 Then
820821
Err.Raise vbObjectError, , ERR_INVALID_ARCHIVE & ". " & ERR_MISSING_ECD_RECORD
821-
GoTo QH
822822
End If
823823
If uEndHdr.LenCom > 0 Then
824824
ReDim baComment(0 To uEndHdr.LenCom - 1) As Byte

test/vbzip/cVbZip.cls

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ Public Function Init(vArgs As Variant) As Boolean
147147
sText = sText & " " & Right$(Space(10) & Format$(lTotalCompressed, "0"), 10)
148148
sText = sText & " " & Format$(lCount, "0") & " file(s)"
149149
ConsolePrint sText & vbCrLf
150-
Else
150+
ElseIf m_oArchive.FileCount > 0 Then
151151
ConsolePrint "No matches found" & vbCrLf
152+
Else
153+
ConsolePrint "Archive is empty" & vbCrLf
152154
End If
153155
Case "t"
154156
If LenB(.Item("zip")) = 0 Then

0 commit comments

Comments
 (0)