Negative encoding value crashes the decoder

Open Beginner friendly
#6 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
swift
Domain
tooling

Research direction

Start in String.Encoding+JSONCodable.swift:107 and trace the numeric handling through Value.swift:94. Run the reproducer with negative and above-Int.max encoding values, then verify decoding throws an error instead of trapping and that xcprojformatter no longer exits with a crash.

Written by the indexing model from the issue text.

Description

A file reference with a negative encoding traps instead of throwing:

let json = #"{"default-configuration":"Debug","localizations":{"development":"en"},"files":[{"path":"a.txt","encoding":-1}]}"#
_ = try XCSchema.Project(jsonRepresentation: Data(json.utf8))
// Fatal error: Negative value is not representable

xcprojformatter dies the same way (exit 133).

It's UInt(Int(with: coder)) in String.Encoding+JSONCodable.swift:107. Values above Int.max (e.g. 9223372036854775808) crash too, because NSNumber.intValue in Value.swift:94 wraps them negative. UInt(exactly:) plus a thrown error would fix it.

main @ c132630, macOS 26, Swift 6.3.3

Dominant language
Swift
Stars
384
Forks
12
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apple/xcode-project-format

All issues in apple/xcode-project-format

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.