diff options
author | 2012-02-21 06:29:54 +0000 | |
---|---|---|
committer | 2012-02-21 06:29:54 +0000 | |
commit | fe763516ae63cd09015514bb0469a30110ed5dec (patch) | |
tree | d7a615643cd1877b41eee7d739ab8a108d923ad0 | |
parent | 1824c80bdde513479188c2f0cc0ba1219e874000 (diff) |
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.
-rw-r--r-- | src/emu/hash.c | 26 | ||||
-rw-r--r-- | src/emu/romload.c | 9 | ||||
-rw-r--r-- | src/lib/util/hashing.c | 4 |
3 files changed, 23 insertions, 16 deletions
diff --git a/src/emu/hash.c b/src/emu/hash.c index 9d03e5cf9ba..76053a4d939 100644 --- a/src/emu/hash.c +++ b/src/emu/hash.c @@ -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) { diff --git a/src/emu/romload.c b/src/emu/romload.c index 78164fcee0c..99acddceef0 100644 --- a/src/emu/romload.c +++ b/src/emu/romload.c @@ -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++; - } -*/ } diff --git a/src/lib/util/hashing.c b/src/lib/util/hashing.c index a1e3112adc6..618750b1946 100644 --- a/src/lib/util/hashing.c +++ b/src/lib/util/hashing.c @@ -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)) |