Commit Graph

11 Commits

Author SHA1 Message Date
Georges-Antoine Assi
dfc4f6a6f5 fix(archives): end bsdtar options before the member argument
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 07:48:05 -04:00
Georges-Antoine Assi
969d9b3f9e fix(archives): fail archive hashing when a member can't be read
A member that failed or timed out mid-archive ended the member stream
silently, so the caller kept the composite hash built from the members
that happened to succeed. Raise ArchiveReadError instead and fall back to
hashing the archive's raw bytes, with no archive_members recorded.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 07:37:39 -04:00
Georges-Antoine Assi
dc981f51c8 fix(archives): read RAR archives through bsdtar so they can be hashed
The bundled 7zz is built without the RAR codec (unRAR license), so it can
neither list nor extract RAR members. Every content-based match silently
came up empty for .rar: no RetroAchievements hash and no CRC/MD5/SHA-1 for
hash-database providers.

RAR listing and extraction now go through libarchive's bsdtar, added to the
images as libarchive-tools. Listing uses an mtree rewrite (libarchive's only
machine-readable listing) and member names are escaped before being handed
back to bsdtar, which matches them as globs.

Fixes #3884

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 10:13:50 -04:00
Spinnich
e6c1ca8487 fix(archives): address extraction review findings from PR #3813
Disable 7zz wildcard matching (-spd) when extracting a named member: a
member literally named with "*" or "?" would otherwise act as a pattern,
matching other members and concatenating them into the -so stream, which
would hash plausible-but-wrong data. Applied to all three extraction
call sites, including the two pre-existing readers that share the
hazard. Verified against the production Alpine 7zz build.

Route extraction stderr to an unlinked temp file instead of a pipe: a
filled pipe blocks 7zz while the parent waits on stdout.read(), which
the chunk-based deadline never interrupts. A file-backed stderr applies
no backpressure and is still read back for the error log on failure.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 20:34:44 +00:00
Spinnich
e24b40a4eb docs(archives): correct RAR support claim in read_rar_archive_files
The bundled Alpine 7zz build lacks the RAR codec: listing RAR members
works, but streaming their contents fails with "Unsupported Method"
(verified against the production image).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 20:11:21 +00:00
Spinnich
b7c60e63a3 fix(retroachievements): extract non-zip archives before RAHasher hashing
RAHasher only decompresses .zip archives itself; any other container
(.7z, .rar, .gz, .bz2, .xz, .tar, ...) was hashed as its raw archive
bytes, silently storing a well-formed hash that matches nothing on
RetroAchievements (issue #3808).

Non-zip archives on buffer-hash platforms are now extracted to a temp
file via the bundled 7zz binary and the extracted ROM is hashed instead.
The new extract_largest_archive_member helper follows the existing 7zz
subprocess patterns, handles single-stream formats whose listings carry
no Attributes line (.gz/.xz), and unwraps one level of nesting so
compressed tarballs (.tgz) reach the ROM inside the inner tar.

Arcade is exempt: its RA hash is computed from the file's basename, so
any container format already hashes correctly and extraction (which
renames the file) would break it. Disc platforms keep their existing
archive skip.

When extraction fails (corrupt archive, or a codec the 7zz build lacks,
e.g. RAR) no hash is stored at all and the 7zz stderr reason is logged
at error level, so scan logs explain the missing hash instead of
silently storing a garbage one.

Fixes #3808

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 20:06:12 +00:00
zurdi
649ddce2aa feat: Implement fine-grained permission checks and admin CRUD for permission groups
- Added new permission handling in `backend/handler/auth/dependencies.py` to support fine-grained, DB-backed permission checks.
- Enhanced user role update logic in `backend/endpoints/user.py` to prevent demotion of the last admin.
- Introduced `hidden_platform_ids` and `hidden_rom_ids` parameters in various database handlers to manage visibility based on admin settings.
- Created new endpoints for managing permission groups, user memberships, and hidden entities in `backend/tests/endpoints/test_permissions_admin.py`.
- Added tests for permissions visibility and CRUD operations in `backend/tests/endpoints/test_permissions_visibility.py` and `backend/tests/endpoints/test_permissions_me.py`.
- Updated archive handling in `backend/utils/archives.py` to improve error logging and timeout management during extraction.
2026-06-24 08:45:45 +00:00
Georges-Antoine Assi
207d0dc4c6 feat(hashing): persist per-member hashes on archive RomFile
Internal members of multi-file archives (zip/tar/7z/rar) are now hashed
individually (crc/md5/sha1) and stored in a new `archive_members` JSON
column on the archive's RomFile, alongside the existing composite hash
used for hash-database matching. Only the archive itself is surfaced as
a RomFile so full_path keeps pointing at a file that exists on disk,
which is the constraint that previously forced us to choose between
composite-only or broken downloads.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 09:41:04 -04:00
Georges-Antoine Assi
9111f70d0a refactor(filesystem): merge archive_7zip.py into archives.py
Consolidate all archive readers (zip/tar/7z/rar) and 7z-internal helpers
into a single utils/archives.py module to keep the archive surface area
in one place.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 09:10:01 -04:00
Georges-Antoine Assi
a1194dc5e0 changes from bot review 2026-05-28 09:02:26 -04:00
Georges-Antoine Assi
438c03facc refactor(filesystem): extract archive/CHD helpers to utils/archives.py
Pull file/archive readers (zip/tar/gz/bz2/7z), CHD parsing, and the
shared libmagic MIME detector out of roms_handler.py into a new
utils/archives.py. Rename the previously underscore-prefixed
read_zip_archive_files / read_tar_archive_files to match the existing
read_7z_archive_files convention, and consolidate the duplicated
"with lock: detector.from_file()" pattern into a detect_mime_type helper.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 08:41:45 -04:00