mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
* fix(scan): hash compressed ROMs by their content in every format Files inside a game folder and standalone single-stream files picked a reader from a hand-written extension/MIME chain that treated plain .gz as tar, missed .tgz/.txz/.xz and the application/gzip MIME spelling, and called max() on empty archives. One suffix-then-MIME lookup in utils/archives now picks the reader, plain gzip/bz2/xz streams are decompressed (or read as a tarball when they hold one), and an empty or unreadable archive falls back to hashing its raw bytes. Fixes #5328 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(scan): don't read a zero-prefixed compressed stream as an empty tar Addresses Greptile review on #5537: tarfile.is_tarfile accepts a zero-filled opening, so a plain .iso.bz2 or .iso.gz starting with zeros fell back to its compressed bytes. A tarball now needs a first member. Also moves hash_largest_member's failure contract into Returns:. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(scan): fall back to raw bytes on more unreadable archives (code-review) Catch ValueError from corrupt Deflate64 members and undecodable zip names, treat an archive with empty content as unreadable, route zips with methods zipfile can't decode through 7zz, and drop the zlib.error handlers no reader raises any more. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(scan): route 7z and undecodable zips through one largest-member reader (simplify) Replace hash_largest_7z_member with a read_7z_file iterator built on the shared 7zz listing and streaming helpers, probe zips with _undecodable_zip_method instead of inspecting the exception cause, share one decompression error tuple, snapshot only the ROM-level accumulators, and reuse the archive-writing test helpers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(scan): bound, single-pass and RAR-aware largest-member hashing - Every Python-side archive read (zip, tar, gzip, bz2, xz, and the composite zip/tar readers) now shares the SEVEN_ZIP_TIMEOUT budget the 7zz and bsdtar paths already had, so a decompression bomb falls back to the raw bytes instead of tying up a scan thread. - Compressed tarballs are read in one streaming pass: each member larger than every one before it is hashed into a copy of the hashers as it passes, instead of listing the whole archive and then decompressing it again to reach the largest member. - gzip is decompressed member by member and ignores trailing bytes the way gunzip does, instead of discarding the content when padding follows the last member. - RAR members inside game folders hash by their largest member through bsdtar. - ARCHIVE_FORMAT_BY_SUFFIX moves to utils.filesystem and is the single suffix list: COMPRESSED_FILE_EXTENSIONS, RAR_FILE_EXTENSIONS and the handler's ARCHIVE_READERS are built from it. - _calculate_rom_hashes detects the MIME type once per file and reads the embedded CHD hash in the same thread, so libmagic no longer runs twice per file or on the event loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>