666ghj/MiroFish · error · StarHistoryError

reviewed avatar data is invalid

Error message

reviewed avatar data is invalid

What it means

Raised by _validate_svg when base64.b64decode(OWNER_AVATAR_BASE64, validate=True) throws ValueError — the hard-coded avatar constant is not valid strict base64. This validates the script's own embedded constants (not user input), so hitting it means the source constant was corrupted or malformed during an edit. The original exception is chained via 'from exc'.

Source

Thrown at scripts/star_history.py:1253

                if local_name != "image" or value not in {
                    OWNER_AVATAR_DATA_URI,
                    WATERMARK_LOGO_DATA_URI,
                }:
                    raise StarHistoryError("generated SVG contains an external resource")
            lowered = value.lower().replace(" ", "")
            if "url(" in lowered and lowered not in {
                "url(#xkcdify)",
                "url(#clip-circle-title)",
            }:
                raise StarHistoryError("generated SVG contains an external resource")
            if lowered.startswith(("http:", "https:", "//")):
                raise StarHistoryError("generated SVG contains an external resource")
    if avatar_count != 1 or watermark_count != 1:
        raise StarHistoryError("generated SVG must contain both reviewed images")
    try:
        avatar = base64.b64decode(OWNER_AVATAR_BASE64, validate=True)
    except ValueError as exc:
        raise StarHistoryError("reviewed avatar data is invalid") from exc
    if (
        len(avatar) > MAX_INLINE_AVATAR_BYTES
        or hashlib.sha256(avatar).hexdigest() != OWNER_AVATAR_SHA256
        or _reviewed_avatar_dimensions(avatar) != OWNER_AVATAR_DIMENSIONS
    ):
        raise StarHistoryError("reviewed avatar data is invalid")
    try:
        watermark = base64.b64decode(WATERMARK_LOGO_BASE64, validate=True)
    except ValueError as exc:
        raise StarHistoryError("reviewed watermark data is invalid") from exc
    png_header = (
        watermark.startswith(b"\x89PNG\r\n\x1a\n")
        and watermark[8:12] == (13).to_bytes(4, "big")
        and watermark[12:16] == b"IHDR"
        and len(watermark) >= 33
    )
    watermark_dimensions = (
        (

View on GitHub (pinned to b5b53acc57)

Solutions

  1. Regenerate the constant programmatically from the actual image file: base64.b64encode(path.read_bytes()).decode('ascii') with no reformatting, and paste it verbatim.
  2. Verify with python -c "import base64;base64.b64decode(open(...).read(), validate=True)" style strict decoding before running the script.
  3. Update the paired constants in the same commit: OWNER_AVATAR_SHA256 and OWNER_AVATAR_DIMENSIONS (64x64), else error 207 fires next.
  4. Check the git diff of line 49 for merge-conflict artifacts or line wrapping.

Example fix

# before: hand-pasted, line-wrapped base64
OWNER_AVATAR_BASE64 = "/9j/2wCEAAgGBgcG...
CAgGBgcG..."  # wraps/typos -> ValueError

# after: generate atomically from the reviewed file
import base64, pathlib
OWNER_AVATAR_BASE64 = base64.b64encode(
    pathlib.Path("assets/owner-avatar-64.jpg").read_bytes()
).decode("ascii")
Defensive patterns

Strategy: validation

Validate before calling

import base64

try:
    base64.b64decode(OWNER_AVATAR_BASE64, validate=True)
except ValueError:
    raise SystemExit("OWNER_AVATAR_BASE64 is not strict base64; regenerate it")

Try / catch

try:
    _validate_svg(svg_bytes)
except StarHistoryError as exc:
    if "avatar data is invalid" in str(exc) and isinstance(exc.__cause__, ValueError):
        # the base64 literal itself is malformed; regenerate it from the source image
        ...

Prevention

When it happens

Trigger: Editing OWNER_AVATAR_BASE64 (scripts/star_history.py:49) by hand: whitespace/newlines inserted, a character outside the base64 alphabet, wrong padding, or a truncated copy-paste of the JPEG's base64. validate=True makes b64decode reject any non-alphabet byte.

Common situations: Replacing the owner avatar: pasting base64 from a website that wraps lines or URL-safe-encodes (-/_ instead of +//); truncation by an editor or diff tool; a bad merge conflict resolution inside the giant string literal.

Related errors


AI-assisted analysis of 666ghj/MiroFish@b5b53acc57 (2026-08-14). Data as JSON: /api/errors/6f6ca5fdbc931d62. Report an issue: GitHub.