From 073813f3e78bdc23618a8589551f9dc4a283f6d4 Mon Sep 17 00:00:00 2001 From: architect-bot Date: Wed, 19 Aug 2026 12:37:46 +0000 Subject: [PATCH] =?UTF-8?q?WIP=20checkpoint:=20US-1:=20Asset=20Import=20Pi?= =?UTF-8?q?peline=20=E2=80=94=20glTF=20upload=20endpoint=20with=20metadata?= =?UTF-8?q?=20extraction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/gltf.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/app/services/gltf.py b/backend/app/services/gltf.py index d84c386..fab388d 100644 --- a/backend/app/services/gltf.py +++ b/backend/app/services/gltf.py @@ -19,6 +19,10 @@ _GLB_MAGIC_INT = 0x46546C67 # b"glTF" interpreted as little-endian uint32 _GLB_JSON_CHUNK_TYPE = 0x4E4F534A # "JSON" _GLB_BIN_CHUNK_TYPE = 0x004E4942 # "BIN\0" +# Whitespace allowed around a GLB JSON chunk. The spec pads with spaces (0x20), +# but be lenient with null bytes and other whitespace that real exporters emit. +_JSON_CHUNK_TRIM = b" \t\r\n\x00" + def looks_like_gltf(content: bytes, filename: Optional[str] = None) -> bool: """Return True when the bytes or filename indicate a glTF/GLB asset.""" @@ -65,7 +69,7 @@ def _parse_glb(content: bytes) -> dict[str, Any]: chunk_data = content[offset:chunk_end] if chunk_type == _GLB_JSON_CHUNK_TYPE: try: - json_chunk = json.loads(chunk_data.decode("utf-8")) + json_chunk = json.loads(chunk_data.strip(_JSON_CHUNK_TRIM).decode("utf-8")) except (ValueError, UnicodeDecodeError) as exc: raise ValueError(f"invalid GLB JSON chunk: {exc}") from exc