fix(runtime): decode the shebang probe leniently so a multi-byte char at byte 256 can't hide the interpreter - #150
Merged
Conversation
… at byte 256 can't hide the interpreter The shebang parser reads the first 256 bytes and decoded them with a strict UTF-8 String(data:encoding:). When a multi-byte character — an em-dash in a header comment — straddled that boundary, the truncated sequence made the whole decode return nil, the shebang was reported absent, and the plugin fell back to /bin/bash. For a Python plugin that means a bash syntax error: a spurious non-zero exit from vee lint, vee render, and the app itself, while running the plugin directly worked. Decode leniently instead (same policy PluginSource documents): the truncated tail becomes U+FFFD, which can only land past the first line, and the shebang parses exactly as written.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A plugin whose header comments contain an em-dash could fail
vee lintandvee renderwith a spurious non-zero exit, while running the same file directly(
python3 plugin.py) worked and printed valid output. The failure waspositional, not "em-dash present" — plugins with em-dashes elsewhere were fine,
which made it look content-sensitive and led to plugins being rewritten with
ASCII hyphens as a workaround.
The cause is in the shebang probe.
PluginExecutor.shebang(of:)reads the first256 bytes of the file and decoded them with a strict
String(data:encoding:.utf8). An em-dash is three bytes (E2 80 94); when onestraddled the 256-byte boundary, the truncated sequence made the entire decode
return
nil. The shebang was then reported absent andlaunchCommandfell backto
/bin/bash <path>— so a Python plugin was handed to bash, which died with asyntax error on the first
print(...). That produced the non-zero exit invee lint,vee render, and the app itself (PluginCoordinatorgoes throughthe same
launchCommand).The fix is to decode leniently with
String(decoding:as:UTF8.self), the samepolicy
PluginSourcealready documents for reading plugin text: a truncatedtail becomes U+FFFD, which can only land past the first line, and the shebang
parses exactly as written. This was the only truncated read paired with a strict
decode in
Sources/.Type of change
<vee.*>capability)examples/) or SDK example (plugins/)Testing done
swift buildswift testswift run vee(manual check in the menu bar)xcodegen generate+xcodebuild(if the app target is affected)npm testinplugins/(if the TypeScript SDK is affected)Regression test:
ShebangLaunchTests.testHonorsShebangWhenMultibyteCharacterStraddlesReadBoundarybuilds the straddling file byte-precisely (with a setup assertion that byte 255
is
0xE2, so the test can't silently stop covering the boundary). It failsbefore the fix and passes after.
End-to-end, with a Python plugin whose header em-dash starts at byte 255:
swiftlint lint --strictalso reports 0 violations across 286 files.Checklist
committed — n/a, no format change.
already describe.