#19 Fixed possible hard Crash when scanning files.
This commit is contained in:
@@ -26,11 +26,7 @@ namespace ROMVault2.SupportedFiles.Files
|
|||||||
bSHA1 = null;
|
bSHA1 = null;
|
||||||
crc = null;
|
crc = null;
|
||||||
|
|
||||||
Stream ds;
|
Stream ds=null;
|
||||||
int errorCode = IO.FileStream.OpenFileRead(filename, out ds);
|
|
||||||
if (errorCode != 0)
|
|
||||||
return errorCode;
|
|
||||||
|
|
||||||
CRC32Hash crc32 = new CRC32Hash();
|
CRC32Hash crc32 = new CRC32Hash();
|
||||||
|
|
||||||
MD5 md5 = null;
|
MD5 md5 = null;
|
||||||
@@ -38,24 +34,39 @@ namespace ROMVault2.SupportedFiles.Files
|
|||||||
SHA1 sha1 = null;
|
SHA1 sha1 = null;
|
||||||
if (testDeep) sha1 = SHA1.Create();
|
if (testDeep) sha1 = SHA1.Create();
|
||||||
|
|
||||||
long sizetogo = ds.Length;
|
try
|
||||||
|
|
||||||
while (sizetogo > 0)
|
|
||||||
{
|
{
|
||||||
int sizenow = sizetogo > Buffersize ? Buffersize : (int)sizetogo;
|
int errorCode = IO.FileStream.OpenFileRead(filename, out ds);
|
||||||
|
if (errorCode != 0)
|
||||||
|
return errorCode;
|
||||||
|
|
||||||
ds.Read(Buffer, 0, sizenow);
|
long sizetogo = ds.Length;
|
||||||
crc32.TransformBlock(Buffer, 0, sizenow, null, 0);
|
|
||||||
if (testDeep) md5.TransformBlock(Buffer, 0, sizenow, null, 0);
|
while (sizetogo > 0)
|
||||||
if (testDeep) sha1.TransformBlock(Buffer, 0, sizenow, null, 0);
|
{
|
||||||
sizetogo -= sizenow;
|
int sizenow = sizetogo > Buffersize ? Buffersize : (int)sizetogo;
|
||||||
|
|
||||||
|
ds.Read(Buffer, 0, sizenow);
|
||||||
|
crc32.TransformBlock(Buffer, 0, sizenow, null, 0);
|
||||||
|
if (testDeep) md5.TransformBlock(Buffer, 0, sizenow, null, 0);
|
||||||
|
if (testDeep) sha1.TransformBlock(Buffer, 0, sizenow, null, 0);
|
||||||
|
sizetogo -= sizenow;
|
||||||
|
}
|
||||||
|
|
||||||
|
crc32.TransformFinalBlock(Buffer, 0, 0);
|
||||||
|
if (testDeep) md5.TransformFinalBlock(Buffer, 0, 0);
|
||||||
|
if (testDeep) sha1.TransformFinalBlock(Buffer, 0, 0);
|
||||||
|
|
||||||
|
ds.Close();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
if (ds != null)
|
||||||
|
ds.Close();
|
||||||
|
|
||||||
|
return 0x17;
|
||||||
}
|
}
|
||||||
|
|
||||||
crc32.TransformFinalBlock(Buffer, 0, 0);
|
|
||||||
if (testDeep) md5.TransformFinalBlock(Buffer, 0, 0);
|
|
||||||
if (testDeep) sha1.TransformFinalBlock(Buffer, 0, 0);
|
|
||||||
|
|
||||||
ds.Close();
|
|
||||||
|
|
||||||
crc = crc32.Hash;
|
crc = crc32.Hash;
|
||||||
if (testDeep) bMD5 = md5.Hash;
|
if (testDeep) bMD5 = md5.Hash;
|
||||||
|
|||||||
Reference in New Issue
Block a user