{"record":{"id":"5bb07c96ed10210c","repo":"roboflow/supervision","slug":"createml-annotation-refers-to-image-image-name-5bb07c","errorCode":null,"errorMessage":"CreateML annotation refers to image {image_name}, which produces an invalid path: {exc}","messagePattern":"CreateML annotation refers to image (.+?), which produces an invalid path: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/dataset/formats/createml.py","lineNumber":32,"sourceCode":"    from supervision.dataset.core import DetectionDataset\n\nCreateMLDict = dict[str, Any]\n\n\ndef _resolve_image_path(images_directory_path: str, image_name: str) -> str:\n    \"\"\"Resolve and validate an image path against the images directory.\n\n    Rejects annotations whose ``image`` field escapes ``images_directory_path``\n    (via ``..`` traversal, an absolute path, or a symlink pointing outside),\n    mirroring the protection used by the COCO loader. Returns the canonical\n    resolved path so aliases collapse to a single dataset entry.\n    \"\"\"\n    images_directory_resolved = Path(images_directory_path).resolve()\n    image_path = Path(images_directory_path) / Path(image_name)\n    try:\n        resolved_image_path = image_path.resolve()\n    except (OSError, ValueError) as exc:\n        raise ValueError(\n            f\"CreateML annotation refers to image {image_name!r}, which \"\n            f\"produces an invalid path: {exc}\"\n        ) from exc\n    if resolved_image_path == images_directory_resolved:\n        raise ValueError(\n            f\"CreateML annotation refers to image {image_name!r}, which \"\n            f\"resolves to the images directory itself \"\n            f\"({images_directory_resolved}). Expected a path to an image file.\"\n        )\n    if images_directory_resolved not in resolved_image_path.parents:\n        raise ValueError(\n            f\"CreateML annotation refers to image {image_name!r}, which \"\n            f\"resolves to {resolved_image_path} — outside the images \"\n            f\"directory {images_directory_resolved}.\"\n        )\n    if resolved_image_path.is_dir():\n        raise ValueError(\n            f\"CreateML annotation refers to image {image_name!r}, which \"","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/dataset/formats/createml.py#L14-L50","documentation":"Raised by _resolve_image_path in the CreateML loader when Path.resolve() raises OSError or ValueError while resolving the joined image path. It wraps the OS-level resolution failure with the offending image name, before the containment checks run.","triggerScenarios":"A CreateML entry whose image string contains an embedded NUL byte (ValueError from OS path APIs) or triggers an OSError during resolution on the host filesystem.","commonSituations":"Corrupted or binary-mangled annotation files; strings built from byte buffers with stray NULs; platform-specific path length limits.","solutions":["Print repr(entry['image']) to find hidden characters, then strip NULs and control chars.","Repair the JSON: sanitize each image field to a plain ASCII/UTF-8 filename.","Regenerate the file from source data."],"exampleFix":"// before\n{\"image\": \"img\\u0000.jpg\"}\n\n// after\n{\"image\": \"img.jpg\"}","handlingStrategy":"validation","validationCode":"import json\nfrom pathlib import Path\n\ndef sanitize_createml_images(annotations_path: str) -> int:\n    \"\"\"Strip NUL/control characters from 'image' fields; return count fixed.\"\"\"\n    entries = json.loads(Path(annotations_path).read_text())\n    fixed = 0\n    for e in entries:\n        clean = \"\".join(ch for ch in e[\"image\"] if ch.isprintable())\n        if clean != e[\"image\"]:\n            e[\"image\"], fixed = clean, fixed + 1\n    Path(annotations_path).write_text(json.dumps(entries))\n    return fixed","typeGuard":"def is_resolvable_createml_image(name: str) -> bool:\n    \"\"\"True when the string contains no NUL bytes or control characters.\"\"\"\n    return isinstance(name, str) and all(ch.isprintable() for ch in name)","tryCatchPattern":"try:\n    sv.DetectionDataset.from_createml(images_directory_path=d, annotations_path=a)\nexcept ValueError as exc:\n    if \"invalid path\" in str(exc):\n        sanitize_createml_images(a)\n    else:\n        raise","preventionTips":["Inspect odd values with repr() to reveal embedded control characters.","Validate downloaded annotation files with a checksum before loading.","Keep annotation generation purely text-based (UTF-8 JSON dumps)."],"tags":["createml","dataset-load","path-validation","corruption"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}