Skip to content

panic: nil pointer dereference in CreateDiagnosticForNodeInSourceFile for a malformed "files" array in tsconfig.json #65079

Open

Description

🔎 Search Terms

panic, nil pointer dereference, tsconfig, files, TS18002, CreateDiagnosticForNodeInSourceFile, parseJsonConfigFileContentWorker

🕗 Version & Regression Information

Crashes in 7.0.2 and in 7.1.0-dev.20261031.1 (main at 6161772). TypeScript 6.0.3 does not crash.

💻 Code

// tsconfig.json
{"files":[}]}

Run tsc -p tsconfig.json.

🙁 Actual behavior

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=...]

goroutine 1 [running]:
github.com/microsoft/TypeScript/tsc/internal/tsoptions.CreateDiagnosticForNodeInSourceFile(..., 0x0, ...)
	tsc/internal/tsoptions/errors.go:93
github.com/microsoft/TypeScript/tsc/internal/tsoptions.parseJsonConfigFileContentWorker(...)
	tsc/internal/tsoptions/tsconfigparsing.go:1200
github.com/microsoft/TypeScript/tsc/internal/tsoptions.ParseJsonSourceFileConfigFileContent(...)
	tsc/internal/tsoptions/tsconfigparsing.go:650

🙂 Expected behavior

The same as TypeScript 6.0.3, which exits 2 with:

error TS18002: The 'files' list in config file '<dir>/tsconfig.json' is empty.
tsconfig.json(1,1): error TS5092: The root value of a 'tsconfig.json' file must be an object.
tsconfig.json(1,11): error TS1137: Expression or comma expected.
tsconfig.json(1,12): error TS1012: Unexpected token.

Additional information about the issue

In the "files list is empty" branch (tsconfigparsing.go:1190-1200), ForEachTsConfigPropArray(sourceFile.SourceFile, "files", ...) returns nil for this malformed JSON, and CreateDiagnosticForNodeInSourceFile dereferences the nil node (errors.go:93). TypeScript 6.0.3 calls createDiagnosticForNodeInSourceFileOrCompilerDiagnostic at this spot, which falls back to a global diagnostic; that's why its TS18002 has no location. The Go equivalent, CreateDiagnosticForNodeInSourceFileOrCompilerDiagnostic, already exists (errors.go:90), so the fix is probably to call it here.

Found by differential fuzzing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions