Skip to content

Parser rejects some binary integers #213

@ghost

Description

The latest commit 22db720 on master rejects the following TOML document:

a = 0b1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000
b = 0b0000100010001000100010001000100010001000100010001000100010001000
c = [0b1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000]

The parser prints for example:

what(): [error] toml::parse_binary_integer:
 --> unknown file
   |
 1 | a = 0b1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000
   |     ^--- too large input (> int64_t)

or a different error message if the number occurs in an array.

The value of these integers is approximately 0.533 * 2^60, easily within the range of a signed 64-bit integer.
So I believe the TOML document is valid.

The latest release v3.7.1 of toml11 parses the document correctly. However, the assignment to b invokes undefined behaviour which can be seen for example by compiling with -fsanitize=undefined.

I'm experimenting with a TOML fuzzer which revealed this issue. I guess most normal applications are not likely to hit this case, so I understand if this gets low priority. It still seems worthwhile to fix it though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions