Be more rigorous about parsing invalid hashes. Report them
only through validity checking. If detected normally, do a best-effort attempt so that things like CRC(1) SHA1(1) can be used to force reporting of proper checksums.
This commit is contained in:
parent
1824c80bdd
commit
fe763516ae
@ -307,7 +307,7 @@ bool hash_collection::from_internal_string(const char *string)
|
||||
|
||||
// loop until we hit it
|
||||
bool errors = false;
|
||||
bool skip_digits = false;
|
||||
int skip_digits = 0;
|
||||
while (ptr < stringend)
|
||||
{
|
||||
char c = *ptr++;
|
||||
@ -316,10 +316,21 @@ bool hash_collection::from_internal_string(const char *string)
|
||||
// non-hex alpha values specify a hash type
|
||||
if (uc >= 'G' && uc <= 'Z')
|
||||
{
|
||||
if (skip_digits != 0)
|
||||
errors = true;
|
||||
skip_digits = 0;
|
||||
if (uc == HASH_CRC)
|
||||
skip_digits = m_has_crc32 = m_crc32.from_string(ptr, stringend - ptr);
|
||||
{
|
||||
m_has_crc32 = true;
|
||||
errors = !m_crc32.from_string(ptr, stringend - ptr);
|
||||
skip_digits = 2 * sizeof(crc32_t);
|
||||
}
|
||||
else if (uc == HASH_SHA1)
|
||||
skip_digits = m_has_sha1 = m_sha1.from_string(ptr, stringend - ptr);
|
||||
{
|
||||
m_has_sha1 = true;
|
||||
errors = !m_sha1.from_string(ptr, stringend - ptr);
|
||||
skip_digits = 2 * sizeof(sha1_t);
|
||||
}
|
||||
else
|
||||
errors = true;
|
||||
}
|
||||
@ -327,11 +338,15 @@ bool hash_collection::from_internal_string(const char *string)
|
||||
// hex values are ignored, though unexpected
|
||||
else if ((uc >= '0' && uc <= '9') || (uc >= 'A' && uc <= 'F'))
|
||||
{
|
||||
if (!skip_digits)
|
||||
if (skip_digits != 0)
|
||||
skip_digits--;
|
||||
else
|
||||
errors = true;
|
||||
}
|
||||
|
||||
// anything else is a flag
|
||||
else if (skip_digits != 0)
|
||||
errors = true;
|
||||
else
|
||||
m_flags.cat(c);
|
||||
}
|
||||
@ -386,9 +401,6 @@ void hash_collection::end()
|
||||
{
|
||||
assert(m_creator != NULL);
|
||||
|
||||
// default to getting nothing
|
||||
m_has_crc32 = m_has_sha1 = false;
|
||||
|
||||
// finish up the CRC32
|
||||
if (m_creator->m_doing_crc32)
|
||||
{
|
||||
|
@ -414,15 +414,6 @@ static void dump_wrong_and_correct_checksums(rom_load_data *romdata, const hash_
|
||||
astring tempstr;
|
||||
romdata->errorstring.catprintf(" EXPECTED: %s\n", hashes.macro_string(tempstr));
|
||||
romdata->errorstring.catprintf(" FOUND: %s\n", acthashes.macro_string(tempstr));
|
||||
/*
|
||||
// warn about any ill-formed hashes
|
||||
for (hash_base *hash = hashes.first(); hash != NULL; hash = hash->next())
|
||||
if (hash->parse_error())
|
||||
{
|
||||
romdata->errorstring.catprintf("\tInvalid %s checksum treated as 0 (check leading zeros)\n", hash->name());
|
||||
romdata->warnings++;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -85,6 +85,7 @@ inline int char_to_hex(char c)
|
||||
bool sha1_t::from_string(const char *string, int length)
|
||||
{
|
||||
// must be at least long enough to hold everything
|
||||
memset(m_raw, 0, sizeof(m_raw));
|
||||
if (length == -1)
|
||||
length = strlen(string);
|
||||
if (length < 2 * sizeof(m_raw))
|
||||
@ -127,6 +128,7 @@ const char *sha1_t::as_string(astring &buffer) const
|
||||
bool md5_t::from_string(const char *string, int length)
|
||||
{
|
||||
// must be at least long enough to hold everything
|
||||
memset(m_raw, 0, sizeof(m_raw));
|
||||
if (length == -1)
|
||||
length = strlen(string);
|
||||
if (length < 2 * sizeof(m_raw))
|
||||
@ -170,6 +172,7 @@ const char *md5_t::as_string(astring &buffer) const
|
||||
bool crc32_t::from_string(const char *string, int length)
|
||||
{
|
||||
// must be at least long enough to hold everything
|
||||
m_raw = 0;
|
||||
if (length == -1)
|
||||
length = strlen(string);
|
||||
if (length < 2 * sizeof(m_raw))
|
||||
@ -221,6 +224,7 @@ void crc32_creator::append(const void *data, UINT32 length)
|
||||
bool crc16_t::from_string(const char *string, int length)
|
||||
{
|
||||
// must be at least long enough to hold everything
|
||||
m_raw = 0;
|
||||
if (length == -1)
|
||||
length = strlen(string);
|
||||
if (length < 2 * sizeof(m_raw))
|
||||
|
Loading…
Reference in New Issue
Block a user