Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash: WhitespaceLinter.contiguousWhitespace(startingAt:in:) #960

Closed
lukbukkit opened this issue Mar 13, 2025 · 2 comments · Fixed by #962
Closed

Crash: WhitespaceLinter.contiguousWhitespace(startingAt:in:) #960

lukbukkit opened this issue Mar 13, 2025 · 2 comments · Fixed by #962

Comments

@lukbukkit
Copy link

When applying swift-format to my project it crashes with following stack trace:

💣 Program crashed: System trap at 0x0000aaaac5d215e0

Thread 0 "swift-format" crashed:

 0 WhitespaceLinter.contiguousWhitespace(startingAt:in:) in swift-format at /home/build-user/swift-format/Sources/SwiftFormat/PrettyPrint/WhitespaceLinter.swift:327:11
 1 WhitespaceLinter.lint() + 660 in swift-format at /home/build-user/swift-format/Sources/SwiftFormat/PrettyPrint/WhitespaceLinter.swift:56:33
 2 SwiftLinter.lint(syntax:operatorTable:assumingFileURL:source:) + 715 in swift-format at /home/build-user/swift-format/Sources/SwiftFormat/API/SwiftLinter.swift:155:8
 3 SwiftLinter.lint(source:assumingFileURL:parsingDiagnosticHandler:) + 307 in swift-format at /home/build-user/swift-format/Sources/SwiftFormat/API/SwiftLinter.swift:101:9
 4 LintFrontend.processFile(_:) + 555 in swift-format at /home/build-user/swift-format/Sources/swift-format/Frontend/LintFrontend.swift:33:18
 5 specialized Sequence.forEach(_:) + 2491 in swift-format at /home/build-user/swift-format/Sources/swift-format/Frontend/Frontend.swift:153:18
 6 implicit closure #7 in Frontend.processURLs(_:parallel:) in swift-format at /home/build-user/swift-format/Sources/swift-format/Frontend/Frontend.swift:153:10
 7 Frontend.processURLs(_:parallel:) + 699 in swift-format at /home/build-user/swift-format/Sources/swift-format/Frontend/Frontend.swift:153:18
 8 Frontend.run() + 199 in swift-format at /home/build-user/swift-format/Sources/swift-format/Frontend/Frontend.swift:102:7
 9 closure #1 in SwiftFormatCommand.Lint.run() + 123 in swift-format at /home/build-user/swift-format/Sources/swift-format/Subcommands/Lint.swift:37:18
10 specialized PerformanceMeasurementsOptions.printingInstructionCountIfRequested<A>(_:) in swift-format at Sources/swift-format/Subcommands/PerformanceMeasurement.swift:24:18
11 SwiftFormatCommand.Lint.run() + 175 in swift-format at /home/build-user/swift-format/Sources/swift-format/Subcommands/Lint.swift:35:41
12 0x0000ffff938f84c4 <unknown> in libc.so.6
13 0x0000ffff938f8598 <unknown> in libc.so.6

Here's how you can reproduce the crash:

# Clone the repository
git clone https://github.com/seemoo-lab/CellGuard.git
# Run swift-format included with the latest swift Docker container
docker run --rm -it -v $(pwd)/CellGuard:/app:ro swift:latest
# Inside the container go to the mounted directory
cd /app/CellGuardAppSwift
# Run swift-format
swift format lint -r .
# At some point, you'll encounter this crash

Best
Lukas

@TTOzzi
Copy link
Member

TTOzzi commented Mar 13, 2025

Hello @lukbukkit!
Thank you for reporting this issue along with the reproduction steps.

I took a quick look into the cause, and it seems that the crash occurs due to a special unicode line separator character(U+2028) present in UserStudyView.swift.

Image

You can check for this character by copying it from here and using Command + F to search for it.
As a temporary workaround, you can simply remove this character to resolve the issue immediately.

@lukbukkit
Copy link
Author

Thanks for your quick reply and the workaround! It fixes the crash. I assume those Unicode characters originate from a PDF from which we copied the text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants