Skip to content

[SR-6699] Swift Compiler allows invisible Unicode characters in identifiers #49248

Open
@swift-ci

Description

@swift-ci
Previous ID SR-6699
Radar None
Original Reporter chockenberry (JIRA User)
Type Bug

Attachment: Download

Environment

macOS 10.12.6, Xcode 9.2 (9C40b)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 7b4afe08acbfae759bbab496dffa94cc

relates to:

  • SR-738 Some emojis can't be used in identifiers / Unicode 5.2
  • SR-6698 Swift Compiler does not check for canonical equivalence of identifiers that use Unicode

Issue Description:

Zero-width joiners and other invisible Unicode characters can be included in identifiers, allowing code to be obfuscated.

For example, with this code:

let ‌‌‌‌‌⁠‌‌‌⁠‌‌‌⁠‌‌‌‌⁠‌⁠‌‌‌⁠‌‌‌‌‌‌⁠‌‌‌‌⁠‌‌‌‌‌⁠‌⁠‌‌‌‌⁠‌‌‌‌‌‌⁠‌‌‌‌‌‌⁠‌⁠‌‌‌‌⁠‌‌‌‌‌⁠‌‌‌‌⁠‌‌‌‌‌⁠‌⁠‌‌‌‌‌⁠‌‌‌‌⁠‌‌‌⁠‌‌‌‌‌⁠‌‌‌‌‌‌foo = 111111111
let ‌‌‌⁠‌‌‌‌⁠‌‌⁠‌‌⁠‌‌‌⁠‌⁠‌‌‌‌‌⁠‌‌⁠‌‌‌⁠‌‌‌⁠‌‌⁠‌⁠‌‌‌⁠‌‌‌‌⁠‌⁠‌‌⁠‌‌‌⁠‌‌‌⁠‌‌‌⁠‌‌‌⁠‌‌‌‌⁠‌⁠‌‌‌⁠‌‌‌⁠‌‌‌‌‌⁠‌‌‌‌⁠‌‌‌⁠‌⁠‌‌‌⁠‌‌‌‌‌⁠‌⁠‌‌‌⁠‌‌‌‌⁠‌‌‌⁠‌‌⁠‌‌‌‌‌bar = 111111111

let bar = 1

‌‌‌‌‌⁠‌‌‌⁠‌‌‌⁠‌‌‌‌⁠‌⁠‌‌‌⁠‌‌‌‌‌‌⁠‌‌‌‌⁠‌‌‌‌‌⁠‌⁠‌‌‌‌⁠‌‌‌‌‌‌⁠‌‌‌‌‌‌⁠‌⁠‌‌‌‌⁠‌‌‌‌‌⁠‌‌‌‌⁠‌‌‌‌‌⁠‌⁠‌‌‌‌‌⁠‌‌‌‌⁠‌‌‌⁠‌‌‌‌‌⁠‌‌‌‌‌‌foo * ‌‌‌⁠‌‌‌‌⁠‌‌⁠‌‌⁠‌‌‌⁠‌⁠‌‌‌‌‌⁠‌‌⁠‌‌‌⁠‌‌‌⁠‌‌⁠‌⁠‌‌‌⁠‌‌‌‌⁠‌⁠‌‌⁠‌‌‌⁠‌‌‌⁠‌‌‌⁠‌‌‌⁠‌‌‌‌⁠‌⁠‌‌‌⁠‌‌‌⁠‌‌‌‌‌⁠‌‌‌‌⁠‌‌‌⁠‌⁠‌‌‌⁠‌‌‌‌‌⁠‌⁠‌‌‌⁠‌‌‌‌⁠‌‌‌⁠‌‌⁠‌‌‌‌‌bar

A developer could be tricked into thinking that the result is 11111111, instead of the actual result of 12345678987654321.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions