Skip to content

json_scanf crashes on valid JSON with empty string key in nested object #82

@AhmedShAli24

Description

@AhmedShAli24

What's happening

When you pass {"a":{"":false}} to json_scanf, it internally calls json_unescape with a null pointer, then does pointer arithmetic on it. That's UB and it crashes every time.

The call chain is: json_scanfjson_vscanfjson_scanf_cbjson_unescape (frozen.c:899, frozen.c:924)

Crash Input:
\"VVVVVVVVVVVVVVVVVVVVVVVVVVVV)"\u0041\u00:1},{"i""

Crashes immediately with a UBSan abort (SIGILL). Tested on clang 18 with -fsanitize=address,undefined.

Note

This is 18 bytes of totally normal JSON. Any application using json_scanf with %Q that might receive nested objects with empty string keys will hit this in production — no adversarial input required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions