lean4-htt/src/Lean/Data/Json
Mario Carneiro 62cdb51ed5
feat: UTF-8 string validation (#3958)
Previously, there was a function `opaque fromUTF8Unchecked : ByteArray
-> String` which would convert a list of bytes into a string, but as the
name implies it does not validate that the string is UTF-8 before doing
so and as a result it produces unsound results in the compiler (because
the lean model of `String` indirectly asserts UTF-8 validity). This PR
replaces that function by
```lean
opaque validateUTF8 (a : @& ByteArray) : Bool

opaque fromUTF8 (a : @& ByteArray) (h : validateUTF8 a) : String
```
so that while the function is still "unchecked", we have a proof witness
that the string is valid. To recover the original, actually unchecked
version, use `lcProof` or other unsafe methods to produce the proof
witness.

Because this was the only `ByteArray -> String` conversion function, it
was used in several places in an unsound way (e.g. reading untrusted
input from IO and treating it as UTF-8). These have been replaced by
`fromUTF8?` or `fromUTF8!` as appropriate.
2024-04-20 18:36:37 +00:00
..
Basic.lean chore: reorganising to reduce imports (#3790) 2024-03-27 11:15:01 +00:00
Elab.lean chore: add missing copyright headers (#3411) 2024-02-20 01:49:55 +00:00
FromToJson.lean chore: revert ToJson/FromJson Sum (#3759) (#3760) 2024-03-25 09:09:44 +00:00
Parser.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Printer.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Stream.lean feat: UTF-8 string validation (#3958) 2024-04-20 18:36:37 +00:00