Puffs,全名为 Parsing Untrusted File Formats Safely ,是 Google 开源的一个用于特定领域的语言和库,可安全地解析不受信任的文件格式,包括图像、音频、视频、字体和压缩档案等。
与 C 语言不同,Puffs 对于缓冲区溢出、整数算术溢出和空指针解引用是非常安全的。Puff 和其他内存安全语言之间的主要区别在于,所有这些检查都是在编译时完成的,而不是在运行时完成的。
Puffs 旨在像 Go 或 Rust 一样生成安全的软件库,同时能像 C 一样快,可以在任何使用 C 库的地方使用。但需注意的是,Puffs 不是一种通用的编程语言,虽然在技术上可行,但似乎不值得去写一个专门的 Puffs 编译器出来。
$ git diff diff --git a/std/gif/decode_lzw.puffs b/std/gif/decode_lzw.puffs index f878c5e..b43443d 100644 --- a/std/gif/decode_lzw.puffs +++ b/std/gif/decode_lzw.puffs @@ -97,8 +97,8 @@ pub func lzw_decoder.decode?(dst ptr buf1, src ptr buf1, src_final bool)() { // type checking, bounds checking and code generation for it). in.dst.write?(x:s) - if use_save_code { - this.suffixes[save_code] = c as u8 + if use_save_code and (c < 200) { + this.suffixes[save_code] = (c + 1) as u8 this.prefixes[save_code] = prev_code as u16 } $ puffs gen std/gif gen wrote: /home/n/go/src/github.com/google/puffs/gen/c/gif.c gen unchanged: /home/n/go/src/github.com/google/puffs/gen/h/gif.h $ puffs test std/gif gen unchanged: /home/n/go/src/github.com/google/puffs/gen/c/gif.c gen unchanged: /home/n/go/src/github.com/google/puffs/gen/h/gif.h test: /home/n/go/src/github.com/google/puffs/test/c/gif gif/basic.c clang PASS (8 tests run) gif/basic.c gcc PASS (8 tests run) gif/gif.c clang FAIL test_lzw_decode: bufs1_equal: wi: got 19311, want 19200. contents differ at byte 3 (in hex: 0x000003): 000000: dcdc dc00 00d9 f5f9 f6df dc5f 393a 3a3a ..........._9::: 000010: 3a3b 618e c8e4 e4e4 e5e4 e600 00e4 bbbb :;a............. 000020: eded 8f91 9191 9090 9090 9190 9192 9192 ................ 000030: 9191 9292 9191 9293 93f0 f0f0 f1f1 f2f2 ................ excerpts of got (above) versus want (below): 000000: dcdc dcdc dcd9 f5f9 f6df dc5f 393a 3a3a ..........._9::: 000010: 3a3a 618e c8e4 e4e4 e5e4 e6e4 e4e4 bbbb ::a............. 000020: eded 8f91 9191 9090 9090 9090 9191 9191 ................ 000030: 9191 9191 9191 9193 93f0 f0f0 f1f1 f2f2 ................ gif/gif.c gcc FAIL test_lzw_decode: bufs1_equal: wi: got 19311, want 19200. contents differ at byte 3 (in hex: 0x000003): 000000: dcdc dc00 00d9 f5f9 f6df dc5f 393a 3a3a ..........._9::: 000010: 3a3b 618e c8e4 e4e4 e5e4 e600 00e4 bbbb :;a............. 000020: eded 8f91 9191 9090 9090 9190 9192 9192 ................ 000030: 9191 9292 9191 9293 93f0 f0f0 f1f1 f2f2 ................ excerpts of got (above) versus want (below): 000000: dcdc dcdc dcd9 f5f9 f6df dc5f 393a 3a3a ..........._9::: 000010: 3a3a 618e c8e4 e4e4 e5e4 e6e4 e4e4 bbbb ::a............. 000020: eded 8f91 9191 9090 9090 9090 9191 9191 ................ 000030: 9191 9191 9191 9193 93f0 f0f0 f1f1 f2f2 ................ puffs-test-c: some tests failed puffs test: some tests failed