VirtualBox

Ticket #9150 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

vhdRead is broken => Fixed in SVN

Reported by: harrumph Owned by:
Priority: major Component: virtual disk
Version: VirtualBox 4.0.10 Keywords: VHD
Cc: Guest type: other
Host type: other

Description

I'm seeing disk corruption converting disks from VHD, and booting VMs. From inspection, this code looks bad...

                cbBuf = cSectors * VHD_SECTOR_SIZE;
                LogFunc(("Sectors free: uVhdOffset=%llu cbBuf=%u\n", uVhdOffset, cbBuf));
                rc = VERR_VD_BLOCK_FREE;
            }
        }
        else
            AssertMsgFailed(("Reading block bitmap failed rc=%Rrc\n", rc));
    }
    else
    {
        rc = vhdFileReadSync(pImage, uOffset, pvBuf, cbBuf, NULL);
    }

    if (RT_SUCCESS(rc))
    {
        if (pcbActuallyRead)
            *pcbActuallyRead = cbBuf;

        Log2(("vhdRead: off=%#llx pvBuf=%p cbBuf=%d\n"
                "%.*Rhxd\n",
                uOffset, pvBuf, cbBuf, cbBuf, pvBuf));
    }

Note - *pcbActuallyRead not updated when a 'free' sector found, so calling code assumes all data in the scope of the read was 'free', when it could just be a single sector.

Contrast with vhdAsyncRead that does this

                cbRead = cSectors * VHD_SECTOR_SIZE;
                LogFunc(("Sectors free: uVhdOffset=%llu cbRead=%u\n", uVhdOffset, cbRead));
                rc = VERR_VD_BLOCK_FREE;
            }
        }
        else
            AssertMsg(rc == VERR_VD_NOT_ENOUGH_METADATA, ("Reading block bitmap failed rc=%Rrc\n", rc));
    }
    else
    {
        rc = vhdFileReadUserAsync(pImage, uOffset, pIoCtx, cbRead);
    }

    if (pcbActuallyRead)
        *pcbActuallyRead = cbRead;

    LogFlowFunc(("returns rc=%Rrc\n", rc));
    return rc;
}

This always indicates the number of bytes actually read (whether 'free' or not).

Change History

comment:1 Changed 3 years ago by aeichner

Thanks for this report! This will be fixed in the next release of VirtualBox.

comment:2 Changed 3 years ago by frank

  • Summary changed from vhdRead is broken to vhdRead is broken => Fixed in SVN

comment:3 Changed 3 years ago by frank

  • Status changed from new to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.

www.oracle.com
ContactPrivacy policyTerms of Use