diff --git a/Sources/TOMLDecoder/Parsing/Parser.swift b/Sources/TOMLDecoder/Parsing/Parser.swift index 3375973..8b0d71a 100644 --- a/Sources/TOMLDecoder/Parsing/Parser.swift +++ b/Sources/TOMLDecoder/Parsing/Parser.swift @@ -1308,6 +1308,9 @@ extension Token { resultCodeUnits.append(bytes[index]) index = text.index(after: index) } + guard index < text.upperBound else { + throw TOMLError(.invalidInteger(context: context, lineNumber: lineNumber, reason: "expected digit after sign")) + } if bytes[index] == CodeUnits.underscore { throw TOMLError(.invalidInteger(context: context, lineNumber: lineNumber, reason: "cannot start with a '_'")) diff --git a/Tests/TOMLDecoderTests/TOMLTableKeyMembershipTests.swift b/Tests/TOMLDecoderTests/TOMLTableKeyMembershipTests.swift index d6464b3..7100229 100644 --- a/Tests/TOMLDecoderTests/TOMLTableKeyMembershipTests.swift +++ b/Tests/TOMLDecoderTests/TOMLTableKeyMembershipTests.swift @@ -45,4 +45,11 @@ struct TOMLTableKeyMembershipTests { try inlineTable.string(forKey: "x") } } + + @Test + func signOnlyIntegerThrowsWithoutTrapping() throws { + #expect(throws: TOMLError.self) { + _ = try Dictionary(TOMLTable(source: "x = +\n")) + } + } }