vasi / qcow2-fuse

Gain access to qcow2 virtual disk images as a user-space filesystem
MIT License
60 stars 5 forks source link

Can't parse qcow2 file: Malformed qcow2 file: header is 112 bytes, file claims 112 #4

Open Sjord opened 3 years ago

Sjord commented 3 years ago

I created an image using qemu-img create -f qcow2 hda.qcow2 5G and installed Debian. When I run qcow2-fuse -d -f hda.qcow2 mount, it gives the error:

Can't parse qcow2 file: Malformed qcow2 file: header is 112 bytes, file claims 112

I am using MacOS 11.3.1.

$ qemu-img info hda.qcow2
image: hda.qcow2
file format: qcow2
virtual size: 5 GiB (5368709120 bytes)
disk size: 1.51 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false
ghost commented 3 years ago

Hi,

I am having the same issue running Arch Linux.

$ qemu-img info disk.qcow2
image: disk.qcow2
file format: qcow2
virtual size: 24 GiB (25769803776 bytes)
disk size: 1.18 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false
Sjord commented 3 years ago

Error originates here.

        let actual_length = io.position();
        try!(self.read_extensions(io));
...
        if self.v3.header_length as u64 != actual_length {
            return Err(Error::FileFormat(format!("header is {} bytes, file claims {}",
                                                 io.position(),
                                                 self.v3.header_length)));
        }

It compares header_length with actual_length, but prints header_length and io.position(). Line 249 assigns io.position() to actual_length, but apparently the io.position() changes after that. My guess is because of read_extensions.

corwin-of-amber commented 2 years ago

@Sjord thanks for finding these! Did you find a fix as well? Would swapping the first two lines work?

Sjord commented 2 years ago

No, unfortunately I didn't find a fix for this.

corwin-of-amber commented 2 years ago

Commenting out the check worked 😆 And I was able to mount an underlying ext4 filesystem using ext4fuse (on masOS).

So perhaps it's just the check that's wrong... Maybe it should be this?

        if self.v3.header_length as u64 != io.position() {
ShadowJonathan commented 1 year ago

I have this same problem

xycainoff commented 1 year ago

having same issue macos 13.4.1

avlec commented 1 year ago

Encountering on MacOS 13.3.1 (a) Do we have any idea at a solution @vasi ?

preland commented 1 year ago

Just encountered this issue as well; idk what's causing it, but I am guessing its an issue of mismatched types or a failure to convert between types