-
-
Notifications
You must be signed in to change notification settings - Fork 389
DMG/bzip2
file read error: bzip2: corrupted input: invalid stream magic
#405
Comments
As the docs say:
You're passing in a stream that gets read, but ignoring the returned stream ( |
Hi Matt, That appears to be a typo on my part from trying to condense the real messy code into a neat reproducer. The error still occurs when the returned stream isn't ignored. I've updated the example accordingly. |
Oh, ok. I will take a look. |
I get the same error with that file, but I also do when just using the underlying bzip2 lib directly. I would open the issue with @dsnet -- he's quite smart and can probably tell you whether it's a bug in bzip2 package or possibly this DMG is malformed. |
Will do. Thank you for the insight! |
Hey, thanks for the ping. It seems to me that the Go stdlib
Strictly speaking, the CLI does not report an error (in terms of a non-zero status code, but does spit out a warning to stderr). Given that data is at least produced, perhaps this requires |
Thanks Joe -- that's a smart idea for troubleshooting. Hmm, yeah, that is tricky then. The file is kind of invalid then? I am not sure how we are going to distinguish that. For now I'm inclined to leave archiver unchanged in this regard and reject faulty inputs. Unless another possibility is introduced. Thanks again for chiming in! |
Funny you should say that. Taking a closer look at the file, it seems like the trailing data is a quirk of $ strings BitcoinTemplate.dmg
...
@@P@
BZh11AY&SYe7
B+"T
@<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>resource-fork</key>
<dict>
<key>blkx</key>
<array>
<dict>
<key>Attributes</key>
<string>0x0050</string>
... (continues for about 100 more lines) It seems like DMG files can be a variety of compression formats.
http://www.newosxbook.com/DMG.html $ strings Rectangle0.80.dmg | tail -n 2
</plist>
koly
$ strings transmission-2.61.dmg | tail -n 2
</plist>
koly
$ strings BitcoinTemplate.dmg | tail -n 2
</plist>
koly Edit: Interestingly, some DMG files are structured in a way where there's no compression/archive headers. # https://www.jetbrains.com/idea/download/?section=mac
$ file -i ideaIU-2024.1.2.dmg
ideaIU-2024.1.2.dmg: application/octet-stream; charset=binary |
@mholt I agree with rejecting faulty inputs, it wouldn't make sense to change this behaviour in general. It could make sense to add some special handling for for |
Sure; but we can only do that if we can seek to the end of the stream -- turns out only a few streams can do that (mainly files and buffers). So we'd only be able to offer a helpful error message in some cases I suppose, but ideally we'd also couple this with a check on the error type rather than relying on string comparison. |
So possible but not easy or reliable. The filename is probably the easiest/most reliable way to identify a
Can you elaborate what you mean by this? I'm happy to open a PR addressing this, with a little guidance. |
@mholt is referring to the ability to distinguishing error values without resorting to doing some form of string parsing on |
Ah yeah that's what I mean. If there's already a specific error value/type then that's perfect, we can probably roll with that. And just seek when it is a Seeker. |
What version of the package or command are you using?
v4.0.0-alpha.8
What are you trying to do?
Decompress a
.dmg
file detected as.bzip2
.$ file -i BitcoinTemplate.dmg BitcoinTemplate.dmg: application/x-bzip2; charset=binary
Note that there is a warning about "trailing garbage" when decompressing it using the CLI, however, it still succeeds.
What steps did you take?
io.ReadAll
What did you expect to happen, and what actually happened instead?
I expected the file to be identified and decompressed successfully.
How do you think this should be fixed?
Unsure.
Please link to any related issues, pull requests, and/or discussion
trufflesecurity/trufflehog#2935
Bonus: What do you use archiver for, and do you find it useful?
The text was updated successfully, but these errors were encountered: