# LLM generated code and utf-8 attacks

**URL:** <https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962>\
**Category:** General\
**Created:** [November 17, 2025, 1:19am UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962 "2025-11-17T01:19:19Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevlar700](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/kevlar700/32/1118_2.png) [@kevlar700](https://forum.ada-lang.io/u/kevlar700)\
**Post date:** [November 17, 2025, 1:19am UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/1 "2025-11-17T01:19:19Z")

</div>

> **[Disrupting the first reported AI-orchestrated cyber espionage campaign](https://www.anthropic.com/news/disrupting-AI-espionage)**
>
> A report describing an a highly sophisticated AI-led cyberattack

Considering how easily LLM server systems can be manipulated via I am told very easy sandbox escaping. And the concern over utf-8 compiler attacks that can embed hidden code exploits. Then even AI clients like copilot thar only suggest code without local binary execution may be attack vectors targetting particular companies or individuals.

Is a good mitigation to use -gnatWb to reject any non ascii code?

---

<div class="post-metadata">

**Author:** ![OneWingedShark](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/onewingedshark/32/305_2.png) [@OneWingedShark](https://forum.ada-lang.io/u/OneWingedShark)\
**Post date:** [November 17, 2025, 2:59am UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/2 "2025-11-17T02:59:10Z")

</div>

> [@kevlar700](#):
>
> And the concern over utf-8 compiler attacks that can embed hidden code exploits.

Meh, Byron already addressed that: all processing is done with UTF-32 (`Wide_Wide_Character`):

1. Converting **all** input to UTF-32, [here](https://github.com/OneWingedShark/Byron/blob/18305e400be9a31d1b1e55a6da4d984c6a8926df/src/reader/readington.adb);
2. Using the definition from the LRM to ensure only valid identifiers, [here](https://github.com/OneWingedShark/Byron/blob/18305e400be9a31d1b1e55a6da4d984c6a8926df/src/internals/spark/byron-internals-spark-pure_types.ads);
3. Ensuring only “[emittable](https://github.com/OneWingedShark/Byron/blob/18305e400be9a31d1b1e55a6da4d984c6a8926df/src/lexer/lexington-aux.ads#L353)” items are put into the token-stream [here](https://github.com/OneWingedShark/Byron/blob/18305e400be9a31d1b1e55a6da4d984c6a8926df/src/lexer/passes/lexington-aux-p20.adb).

**TL;DR —** Correctness mitigates errors, simplicity (e.g. converting everything to `Wide_Wide_Character`) reduces the “surface area” which would be required (i.e. multiple processors).

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [November 17, 2025, 8:17am UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/3 "2025-11-17T08:17:31Z")

</div>

It is too early for Fool’s Day jokes.

---

<div class="post-metadata">

**Author:** ![kevlar700](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/kevlar700/32/1118_2.png) [@kevlar700](https://forum.ada-lang.io/u/kevlar700)\
**Post date:** [November 17, 2025, 8:38am UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/4 "2025-11-17T08:38:49Z")

</div>

Are Bidi control characters the only attack vector and fixed by default in GCC/Gnat?

> **[146100\_trojan-source.pdf](https://media.telefonicatech.com/telefonicatech/uploads/2021/1/146100_trojan-source.pdf)**
>
> 3.08 MB

“There are a variety of ways to exploit the adversarial encoding of source code. The underlying principle is the same in each:  
use Bidi control characters to create a syntactically valid reordering of source code characters in the target language.  
In the following section, we propose three general types of exploits that work across multiple languages. We do not claim that this list is exhaustive.”

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [November 17, 2025, 8:56am UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/5 "2025-11-17T08:56:43Z")

</div>

See ARM 2.3. Bidirectional control characters have Unicode characterization **cf**. As such they cannot be a part of an Ada identifier.

And of course this has nothing to do with the encoding at all be it UTF-8, UTF-16 or UCS-4 (Wide\_Wide.Character).

Of course one can argue that theoretically Wide\_Wide\_Character could give some more opportunities for manipulation because it is larger that the set of valid code points and lacks checks UTF encodings have. But that is rubbish too.

The actual reason why only ASCII-7 should be used is in the homographic glyphs. They remain so even after normalization. E.g. a (U+0061) and а (U+0430).

---

<div class="post-metadata">

**Author:** ![kevlar700](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/kevlar700/32/1118_2.png) [@kevlar700](https://forum.ada-lang.io/u/kevlar700)\
**Post date:** [November 17, 2025, 12:55pm UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/6 "2025-11-17T12:55:35Z")

</div>

> [@dmitry-kazakov](#):
>
> The actual reason why only ASCII-7 should be used is in the homographic glyphs. They remain so even after normalization. E.g. a (U+0061) and а (U+0430).

Can you limit all code to ASCII only?

---

<div class="post-metadata">

**Author:** ![kevlar700](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/kevlar700/32/1118_2.png) [@kevlar700](https://forum.ada-lang.io/u/kevlar700)\
**Post date:** [November 17, 2025, 1:14pm UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/7 "2025-11-17T13:14:09Z")

</div>

I guess the fact that the pie symbol is part of the Ada standard now may be a problem for e.g. No\_Wide\_Characters and -gnaticn though I guess it could possibly just be avoided (assuming it’s just a name of a constant). 🤔

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [November 17, 2025, 4:44pm UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/8 "2025-11-17T16:44:43Z")

</div>

> [@kevlar700](#):
>
> Can you limit all code to ASCII only?

Yes, I can in Ada and I do.

---

<div class="post-metadata">

**Author:** ![kevlar700](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/kevlar700/32/1118_2.png) [@kevlar700](https://forum.ada-lang.io/u/kevlar700)\
**Post date:** [November 17, 2025, 4:56pm UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/9 "2025-11-17T16:56:38Z")

</div>

> [@dmitry-kazakov](#):
>
> Yes, I can in Ada and I do.

I guess I’ll look into simple components then. Would you mind telling me how you do so? Thank you.

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [November 17, 2025, 5:21pm UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/10 "2025-11-17T17:21:27Z")

</div>

> [@kevlar700](#):
>
> Would you mind telling me how you do so?

Identifiers and comments are in English.

String literals can be entered as:

Strings\_Edit.UTF8.Image (16#E4#) – A umlaut

or

Character’Val (16#C4#) & Character’Val (16#A4#)

Needless to say, I use no Wide\_Wide\_Character ever.

Wide\_Character is used exclusively for Windows bindings as a UTF-16 unit.

If you think you needed code points for parsing, matching patterns etc. You are wrong. Here is full parser of Ada expression:

> **[13.9.2. Text output - Simple components for Ada](https://www.dmitry-kazakov.de/ada/components.htm#13.9.2)**
>
> generic package Parsers.Generic\_Ada\_Parser.Generic\_Text\_IO is ... | Simple components for Ada

No Wide\_Wide\_Characters.

---

<div class="post-metadata">

**Author:** ![kevlar700](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/kevlar700/32/1118_2.png) [@kevlar700](https://forum.ada-lang.io/u/kevlar700)\
**Post date:** [November 20, 2025, 11:06am UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/11 "2025-11-20T11:06:46Z")

</div>

I found I already had the following on most of my code bases, though for embedded reasons.

pragma Restrictions (No\_WIde\_Characters);

I added -gnatin to my Alire configuration but sometimes the program compiles and sometimes it picks up illegal characters perhaps depending on whether it compiles in the constant as sometimes using it elsewhere in the code causes it to be picked up but I don’t seem to be able to reliably trigger it.

I seem to be able to compile at times with this which is something I would like to avoid 🤔

```ada
Shadows : constant Character := Ada.Characters.Latin_9.Pound_Sign;
Shаdows : constant Character := Ada.Characters.Latin_9.Ampersand;

```

I also found this

> **[SEC.UB03-050-v1.pdf](https://docs.adacore.com/corp/security-advisories/SEC.UB03-050-v1.pdf)**
>
> 101.73 KB

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [November 20, 2025, 11:48am UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/12 "2025-11-20T11:48:28Z")

</div>

> [@kevlar700](#):
>
> `Latin_9`

Do not do that. The proper way is to consider Character an octet and String UTF-8 encoded:

```ada
with Strings_Edit.UTF8;
...
Pound : constant String := Image (16#A3#);
Ampersand : constant String := Image (16#26#); -- Length 1

```

You never need to convert anything in UTF-8.

---

<div class="post-metadata">

**Author:** ![kevlar700](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/kevlar700/32/1118_2.png) [@kevlar700](https://forum.ada-lang.io/u/kevlar700)\
**Post date:** [November 20, 2025, 12:07pm UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/13 "2025-11-20T12:07:27Z")

</div>

> [@dmitry-kazakov](#):
>
> You never need to convert anything in UTF-8.

Right, always use Latin-1 for UTF-8 compatibility and only for ASCII-7 👍. What I am actually trying to accomplish (not that it’s really a big deal as it would likely get noticed) is that I don’t want any potential trickery like hiding away a Boolean. Even if I don’t use AI or always code by hand from it’s suggestions, others will and it seems nefarious actors can literally control what it provides without any detection by the user and without much difficulty. I want code review to be as straight forward as possible without any shadowing tricks etc.. I don’t want two symbols that look the same in code to be possibly different etc..

```ada
Shadows :
Shаdows :

```

One with a Cyrillic a as you mentioned

---

<div class="post-metadata">

**Author:** ![kevlar700](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/kevlar700/32/1118_2.png) [@kevlar700](https://forum.ada-lang.io/u/kevlar700)\
**Post date:** [December 3, 2025, 3:07pm UTC](https://forum.ada-lang.io/t/llm-generated-code-and-utf-8-attacks/3962/14 "2025-12-03T15:07:41Z")

</div>

So with the following in Alire.toml then either -gnatin works reliably or the shadow constants are banned outright.

```ada
[build-switches]
"*".Source_Encoding = "Compiler_Default"

```
