Comments (3)
I suspect when you created your archive, you didn't pass -mhe=on
. This means that the headers are not encrypted, (as well as being uncompressed), which means that you can read the archive metadata without a password. That's all that OpenReader*()
does, so it never needs to use the password.
If you only used encryption and no compression, then there's no way to detect that the password is wrong without extracting an entire file and computing its CRC32 value and comparing it to the value that's in its FileHeader
struct.
For example, if I create an archive like so:
$ 7z a -ppassword -m0=copy test.7z file1 file2 ...
You can then extract them again using 7z x test.7z
with the wrong password typed in. You'll get each file extracted with the right sizes, but the CRC values won't match, that's your only clue.
If you use compression, then the decompression routine will usually error that the decrypted bytes aren't in a valid format without having to read the whole file.
from sevenzip.
thanks for the answer! I also thought that I would have to manually compare the crc32 file with the value in the archive header.
If this function were in your package/module, it would be a little easier - otherwise, without compressing the archive header, the password does not ensure the identity of the data. I hope I'll add it to the cloned package tomorrow
from sevenzip.
You don't have to compress the headers, you just have to encrypt them; -mhe=on
is independent of -mhc=on|off
, you can mix and match both. If the headers are unencrypted then the code is working as expected as the password is never needed in order to open the archive and list the files, (this is also true with the 7z
utility).
I could compute the CRC32 value on the fly, however:
- An error can only be triggered when calling
Close()
on an opened file after reading the whole file, which means you've already read it in entirety. If you open a file and read anything less than the whole thing, the CRC32 value is meaningless. - It only really makes sense to do this when you're just using encryption and only the copy compression method (i.e. no compression). If you use encryption in combination with any sort of compression, (LZMA, bzip2, etc.) then you'll likely get an error almost immediately when reading a file as the decompression won't produce a valid LZMA, (for example), stream, you won't be able to read the whole file in that case without the correct password.
If you want to compute the CRC yourself, you can do something like this with io.TeeReader()
:
r, err := sevenzip.OpenReaderWithPassword("archive.7z", "password")
if err != nil {
panic(err)
}
defer r.Close()
h := crc32.NewIEEE()
for _, f := range r.File {
rc, err := f.Open()
if err != nil {
panic(err)
}
defer rc.Close()
h.Reset()
tr := io.TeeReader(rc, h)
// Read from tr until EOF
// Now compare h.Sum(nil) with f.CRC32
}
from sevenzip.
Related Issues (20)
- runtime error: index out of range [0] with length 0 HOT 9
- "invalid memory address or nil pointer dereference" when opening 7z file HOT 1
- Errors are not accessible since they are private with a lower case
- Low performance of .7z files with password HOT 2
- Extract files from a self-extracting exe HOT 8
- panic: runtime error: index out of range HOT 2
- low performance for aes7z HOT 2
- warning: a function definition without a prototype is deprecated in all versions HOT 2
- 解带密码的提示 Failed to open file in archive: lzma: unsupported chunk header byte HOT 1
- How to extract HOT 1
- Return list of volume archive files. HOT 14
- seek over file in archive HOT 2
- Support BCJ method HOT 8
- Support PPC method
- Unable to decrypt 7-ZIP file with password (err: breader.ReadByte: no data!) HOT 1
- Unable to decrypt 7-ZIP file with password (err: breader.ReadByte: no data!) HOT 1
- sevenzip as a guide HOT 3
- Add support for reading self-extracting archives
- Empty File processing issue HOT 4
- Fail to read .exe in .7z HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sevenzip.