From a2663ae85d41a7affe489f61a1af1f93ac9a2513 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Tue, 14 Feb 2023 21:31:45 +0100 Subject: [PATCH] Allow compressed resource header length field to be 0 (see #10) --- README.md | 2 ++ src/rsrcfork/compress/common.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1b43fa3..4419d02 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,8 @@ see the ["resource forks" section of the mac_file_format_docs repo](https://gith * Added `open` and `open_raw` methods to `Resource` objects, for stream-based access to resource data. +* Fixed reading of compressed resource headers with the header length field incorrectly set to 0 + (because real Mac OS apparently accepts this). ### Version 1.8.0 diff --git a/src/rsrcfork/compress/common.py b/src/rsrcfork/compress/common.py index 87c6c7c..8eedcee 100644 --- a/src/rsrcfork/compress/common.py +++ b/src/rsrcfork/compress/common.py @@ -46,8 +46,8 @@ class CompressedHeaderInfo(object): raise DecompressError("Invalid header") if signature != COMPRESSED_SIGNATURE: raise DecompressError(f"Invalid signature: {signature!r}, expected {COMPRESSED_SIGNATURE!r}") - if header_length != 0x12: - raise DecompressError(f"Unsupported header length: 0x{header_length:>04x}, expected 0x12") + if header_length not in {0, 0x12}: + raise DecompressError(f"Unsupported header length value: 0x{header_length:>04x}, expected 0x12 or 0") if compression_type == COMPRESSED_TYPE_8: working_buffer_fractional_size, expansion_buffer_size, dcmp_id, reserved = STRUCT_COMPRESSED_TYPE_8_HEADER.unpack(remainder)