<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>I found another critical issue in VHDHDDCore.cpp</DIV>
<DIV> </DIV><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<DIV>static</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> vhdRead(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>void</FONT></FONT><FONT size=2> *pBackendData, uint64_t uOffset, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>void</FONT></FONT><FONT size=2> *pvBuf, size_t cbRead, size_t *pcbActuallyRead)</DIV>
<DIV>{</DIV>
<DIV> </DIV>
<DIV> </DIV><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<DIV>do</DIV></FONT></FONT><FONT size=2>
<DIV>{</DIV>
<DIV>   cSectors++;</DIV>
<DIV>   iBitmap = iBATEntryIndexCurr / 8; </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* Byte in the block bitmap. */</DIV></FONT></FONT><FONT size=2>
<DIV>   iBitInByte = (8 - 1) - (iBATEntryIndexCurr % 8);</DIV>
<DIV>   puBitmap = pImage->pu8Bitmap + iBitmap;</DIV>
<DIV> </DIV>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>  if</FONT></FONT><FONT size=2> (!ASMBitTest(puBitmap, iBitInByte))     <======= THIS CAUSES CRASHES</DIV>
<DIV></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>     break</FONT></FONT><FONT size=2>;</DIV>
<DIV>   iBATEntryIndexCurr++;</DIV>
<DIV>} </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>while</FONT></FONT><FONT size=2> (cSectors < (cbRead / VHD_SECTOR_SIZE));</DIV></FONT>
<DIV> </DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV>The above code contains a buffer overrun bug. The following is an example case, found from my debugger:</DIV>
<DIV> </DIV>
<DIV>pImage->pu8Bitmap, 0x200 in size (pImage->cbDataBlockBitmap = 0x200)</DIV>
<DIV>iBATEntryIndexCurr = 0xfe8</DIV>
<DIV>iBitmap = 0x1fd</DIV>
<DIV>iBitInByte = 0x7</DIV>
<DIV> </DIV>
<DIV>ASMBitTest(puBitmap, iBitInByte) will read pImage->pu8Bitmap at offset of 0x204 (0x1fd + 0x7), definitely over running the 0x200 buf len.</DIV>
<DIV> </DIV>
<DIV>This bug is very tough to catch, but it does occur after extensive test runs. My guess is that some kind of 8-byte alignment should be enforced ?</DIV>
<DIV> </DIV>
<DIV>Let me know if more info is needed,</DIV>
<DIV> </DIV>
<DIV>Huihong</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV></FONT></td></tr></table>