Abstract
As Large Language Models (LLMs) become integral to software development, their ability to accurately comprehend and validate code is paramount. This study investigates the impact of "imperceptible" character-level adversarial attacks—leveraging Unicode features like invisible characters and homoglyphs—on LLM code comprehension. Our findings reveal that while older models like GPT-3.5 degrade gracefully under increasing perturbation, the newer GPT-4o model exhibits a sharp "binary" failure mode, likely due to internal security guardrails.
Introduction
The rapid adoption of LLMs for tasks like code generation, explanation, and vulnerability detection has introduced new security vectors. While natural language adversarial attacks are often detectable by humans, source code offers unique opportunities for "true imperceptibility." By exploiting the Unicode specification, malicious actors can craft code that appears benign to human reviewers but is interpreted incorrectly by automated LLM systems. This study explores the vulnerability of state-of-the-art models to such obfuscation techniques.
Methodology
The researchers developed a black-box framework to evaluate three OpenAI models: gpt-3.5-turbo-0613, gpt-3.5-turbo-0125, and gpt-4o-2024-05-13. The core task required models to perform binary classification: determining if a given JavaScript code snippet matched a provided natural language description.
The study utilized the LeetCode dataset, comprising 2,644 curated code-description pairs. To assess the robustness of the models, the researchers applied four types of character-level perturbations across five "budgets" (20% to 100% of characters affected). Performance was measured through Response Correctness and Model Confidence (derived from token log-probabilities).
Adversarial Attack Types
- Code Reordering: Utilizing the
U+202E(Right-to-Left Override) character to reverse the logical order of strings while maintaining visual correctness in standard UIs. - Invisible Coding Characters: Inserting characters like
U+200C(Zero Width Non-Joiner), which are invisible to humans but processed as distinct tokens by machines. - Code Deletions: Injecting
U+0008(Backspace) characters to visually "erase" preceding characters that remain present in the underlying machine-readable string. - Code Homoglyphs: Replacing standard Latin characters with visually identical characters from different alphabets (e.g., Cyrillic).
Key Results: The GPT-4o "Cliff"
The baseline results showed that all models achieved 100% correctness on clean, unaltered code. However, the introduction of perturbations revealed starkly different failure modes between model generations.
GPT-3.5 models exhibited a linear, "graceful" degradation. For instance, under a 20% deletion budget, gpt-3.5-turbo-0613 correctness dropped to 60.33%, further plummeting to 15.33% at a 100% budget.
In contrast, GPT-4o's performance was characterized by a "cliff." As soon as any perturbation was introduced—even at the minimum 20% budget—correctness dropped to near zero (between 0% and 2.33% across most categories).
Discussion and Security Implications
The researchers hypothesize that GPT-4o's binary failure mode is the result of "deterministic guardrails." The model likely detects unusual Unicode characters and defaults to a "No" response as a safety measure against potential prompt injection or obfuscation. While this behavior results in "incorrect" answers for this specific experimental task, it suggests a heightened sensitivity to adversarial inputs in newer models.
Among the attack vectors, Code Deletions proved the most effective at reducing both confidence and correctness across all tested models. This highlights a significant "blind spot" where human-machine divergence is greatest: changes that a human reviewer would naturally ignore or mentally "correct" can completely derail an LLM's reasoning capabilities.
Conclusion
This study underscores the fragility of LLM-based code comprehension when faced with imperceptible Unicode-based attacks. To mitigate these risks, the authors recommend implementing robust input sanitization layers—such as removing zero-width characters and normalizing Unicode—within LLM pipelines. Future work should focus on developing "vision-aware" processors that can interpret code logic as it appears to humans, rather than relying solely on raw token streams that are susceptible to obfuscation.
Summary updated