10000 fix: Handle CRC being in the unpackInfo (#346) · bodgit/sevenzip@695062b · GitHub
[go: up one dir, main page]

Skip to content

Commit 695062b

Browse files
authored
fix: Handle CRC being in the unpackInfo (#346)
1 parent 9e24d31 commit 695062b

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ The worst scenario would likely be to extract the archive in reverse order.
123123
### Detecting the wrong password
124124

125125
It's virtually impossible to _reliably_ detect the wrong password versus some other corruption in a password protected archive.
126-
This is partly due to how CBC decryption works; with the wrong password you don't get any sort of decryption error, you just a stream of bytes that aren't the correct ones.
126+
This is partly due to how CBC decryption works; with the wrong password you don't get any sort of decryption error, you just get a stream of bytes that aren't the correct ones.
127127
This manifests itself when the file has been compressed _and_ encrypted; during extraction the file is decrypted and then decompressed so with the wrong password the decompression algorithm gets handed a stream which isn't valid so that's the error you see.
128128

129129
A `sevenzip.ReadError` error type can be returned for certain operations.

reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ func (z *Reader) init(r io.ReaderAt, size int64) (err error) {
515515
}
516516

517517
if !fh.isEmptyStream && !fh.isEmptyFile {
518-
f.folder, _ = header.streamsInfo.FileFolderAndSize(j)
518+
f.folder, _, _ = header.streamsInfo.FileFolderAndSize(j)
519519

520520
// Make an exported copy of the folder index
521521
f.Stream = f.folder

struct.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,28 +210,37 @@ func (si *streamsInfo) Folders() int {
210210
return 0
211211
}
212212

213-
func (si *streamsInfo) FileFolderAndSize(file int) (int, uint64) {
214-
total := uint64(0)
215-
213+
func (si *streamsInfo) FileFolderAndSize(file int) (int, uint64, uint32) {
216214
var (
217215
folder int
218216
streams uint64 = 1
217+
crc uint32
219218
)
220219

221220
if si.subStreamsInfo != nil {
221+
total := uint64(0)
222+
222223
for folder, streams = range si.subStreamsInfo.streams {
223224
total += streams
224225
if uint64(file) < total { //nolint:gosec
225226
break
226227
}
227228
}
229+
230+
if len(si.subStreamsInfo.digest) > 0 {
231+
crc = si.subStreamsInfo.digest[file]
232+
}
228233
}
229234

230235
if streams == 1 {
231-
return folder, si.unpackInfo.folder[folder].size[len(si.unpackInfo.folder[folder].coder)-1]
236+
if len(si.unpackInfo.digest) > 0 {
237+
crc = si.unpackInfo.digest[folder]
238+
}
239+
240+
return folder, si.unpackInfo.folder[folder].size[len(si.unpackInfo.folder[folder].coder)-1], crc
232241
}
233242

234-
return folder, si.subStreamsInfo.size[file]
243+
return folder, si.subStreamsInfo.size[file], crc
235244
}
236245

237246
func (si *streamsInfo) folderOffset(folder int) int64 {

types.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -851,11 +851,7 @@ func readHeader(r util.Reader) (*header, error) {
851851
continue
852852
}
853853

854-
if h.streamsInfo.subStreamsInfo != nil {
855-
h.filesInfo.file[i].CRC32 = h.streamsInfo.subStreamsInfo.digest[j]
856-
}
857-
858-
_, h.filesInfo.file[i].UncompressedSize = h.streamsInfo.FileFolderAndSize(j)
854+
_, h.filesInfo.file[i].UncompressedSize, h.filesInfo.file[i].CRC32 = h.streamsInfo.FileFolderAndSize(j)
859855
j++
860856
}
861857

0 commit comments

Comments
 (0)
0