Skip to content

Fix broken --create (JSON repack) round-trip - #13

Open
grub-basket wants to merge 1 commit into
jorio:masterfrom
grub-basket:fix/json-repack-roundtrip
Open

Fix broken --create (JSON repack) round-trip#13
grub-basket wants to merge 1 commit into
jorio:masterfrom
grub-basket:fix/json-repack-roundtrip

Conversation

@grub-basket

Copy link
Copy Markdown

Problem

Repacking a JSON dump back into a resource fork (rsrcdump -c) was broken:

  1. Critical — --create is dead on arrival. do_pack() calls json_to_resource_fork(..., encoding=args.encoding), but that function takes no encoding parameter, so every rsrcdump -c invocation raises TypeError before doing any work. The encoding is already applied globally via set_global_encoding(), so the extra kwarg is just wrong.
  2. High-byte type keys don't round-trip. On extract, the JSON key for a resource type was written with res_type.decode(...), but repack parses it back with parse_type_name() (URL-unquote). Those aren't inverses — a FourCC with a high byte (e.g. b'\xA9icn') or trailing spaces fails to round-trip. Emit the key with sanitize_type_name(), matching the resource sub-directory name and parse_type_name().
  3. Metadata heuristic dropped encoded keys. Repack skipped the metadata block with len(type_name) > 4, which also silently dropped legitimate URL-encoded type keys longer than 4 chars (e.g. %A9icn). Without fixing this, change (2) wouldn't actually help. Match the _metadata key explicitly.
  4. Broken JSON encoder fallback. JSONEncoderBase16Fallback.default() returned a new encoder instance for non-bytes objects instead of super().default(), which would recurse into RecursionError instead of raising a clear TypeError.

Verification

Confirmed an extract-key → json_to_resource_forkfork.pack() round-trip for both a normal FourCC and a high-byte one (%A9ZZb'\xA9ZZ ').


Prepared with Claude Fable 5 (Low effort mode). Automated finding, manually verified — please review before merging.

Repacking a JSON dump back into a resource fork was broken in several ways:

1. Critical: do_pack() passed encoding=args.encoding to
   json_to_resource_fork(), which takes no such argument, so every
   'rsrcdump -c' invocation raised TypeError before doing any work. The
   encoding is already applied globally via set_global_encoding(), so
   drop the extra kwarg.

2. Resource-type JSON keys were written with res_type.decode(), but
   repack parses them with parse_type_name() (URL-unquote). These aren't
   inverses: a FourCC with a high byte (e.g. b'\xA9icn') or trailing
   spaces fails to round-trip. Emit the key with sanitize_type_name(),
   matching the resource sub-directory name and parse_type_name().

3. Repack detected the metadata block with 'len(type_name) > 4', which
   also dropped legitimate URL-encoded type keys longer than 4 chars
   (e.g. '%A9icn'). Match the '_metadata' key explicitly instead. Without
   this, fix (2)'s encoded keys would be silently skipped on repack.

4. JSONEncoderBase16Fallback.default() returned a new encoder instance
   for non-bytes objects instead of delegating to super().default(),
   which would recurse into RecursionError instead of raising a clear
   TypeError. Delegate to super().

Verified an extract-key -> repack round-trip for both normal and
high-byte FourCCs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant