Skip to content

Commit

Permalink
luajit: magic number: raw bits, check with assert
Browse files Browse the repository at this point in the history
  • Loading branch information
dlatchx committed Jun 20, 2023
1 parent 29ab66b commit e44f5c0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
7 changes: 1 addition & 6 deletions format/luajit/luajit.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ type DumpInfo struct {
}

func LuaJITDecodeHeader(di *DumpInfo, d *decode.D) {
magic := d.FieldStr("magic", 3, encoding.Nop)

ok := bytes.Equal([]byte(magic), []byte{0x1b, 0x4c, 0x4a})
if !ok {
d.Errorf("invalid magic number")
}
d.FieldRawLen("magic", 3*8, d.AssertBitBuf([]byte{0x1b, 0x4c, 0x4a})) // ESC 'L' 'J'

d.FieldU8("version")

Expand Down
2 changes: 1 addition & 1 deletion format/luajit/testdata/simple.fqtest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$ fq dv -d luajit simple.luac
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: simple.luac (luajit) 0x0-0x14e.7 (335)
| | | header{}: 0x0-0x17.7 (24)
0x000|1b 4c 4a |.LJ | magic: "\x1bLJ" 0x0-0x2.7 (3)
0x000|1b 4c 4a |.LJ | magic: raw bits (valid) 0x0-0x2.7 (3)
0x000| 02 | . | version: 2 0x3-0x3.7 (1)
| | | flags{}: 0x4-0x4.7 (1)
0x000| 0c | . | raw: 12 0x4-0x4.7 (1)
Expand Down
2 changes: 1 addition & 1 deletion format/luajit/testdata/simple_stripped.fqtest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$ fq dv -d luajit simple_stripped.luac
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: simple_stripped.luac (luajit) 0x0-0xf9.7 (250)
| | | header{}: 0x0-0x4.7 (5)
0x00|1b 4c 4a |.LJ | magic: "\x1bLJ" 0x0-0x2.7 (3)
0x00|1b 4c 4a |.LJ | magic: raw bits (valid) 0x0-0x2.7 (3)
0x00| 02 | . | version: 2 0x3-0x3.7 (1)
| | | flags{}: 0x4-0x4.7 (1)
0x00| 0e | . | raw: 14 0x4-0x4.7 (1)
Expand Down

0 comments on commit e44f5c0

Please sign in to comment.