﻿id,summary,reporter,owner,description,type,status,component,version,resolution,keywords,cc,guest,host
9150,vhdRead is broken => Fixed in SVN,harrumph,,"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).",defect,closed,virtual disk,VirtualBox 4.0.10,fixed,VHD,,other,other
