Puffs,全名为ParsingUntrustedFileFormatsSafely,是Google开源的一个用于特定领域的语言和库,可安全地解析不受信任的文件格式,包括图像、音频、视频、字体和压缩档案等。
与C语言不同,Puffs对于缓冲区溢出、整数算术溢出和空指针解引用是非常安全的。Puff和其他内存安全语言之间的主要区别在于,所有这些检查都是在编译时完成的,而不是在运行时完成的。
Puffs 旨在像Go或Rust一样生成安全的软件库,同时能像C一样快,可以在任何使用C库的地方使用。但需注意的是,Puffs不是一种通用的编程语言,虽然在技术上可行,但似乎不值得去写一个专门的Puffs编译器出来。
$ git diffdiff --git a/std/gif/decode_lzw.puffs b/std/gif/decode_lzw.puffsindex 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/gifgen wrote: /home/n/go/src/github.com/google/puffs/gen/c/gif.cgen unchanged: /home/n/go/src/github.com/google/puffs/gen/h/gif.h$ puffs test std/gifgen unchanged: /home/n/go/src/github.com/google/puffs/gen/c/gif.cgen unchanged: /home/n/go/src/github.com/google/puffs/gen/h/gif.htest: /home/n/go/src/github.com/google/puffs/test/c/gifgif/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 failedpuffs test: some tests failed
评论