From e44f5c00b8b51bff1b5773b44435b4b1c335af58 Mon Sep 17 00:00:00 2001 From: Babz Date: Tue, 20 Jun 2023 23:28:34 +0200 Subject: [PATCH] luajit: magic number: raw bits, check with assert --- format/luajit/luajit.go | 7 +------ format/luajit/testdata/simple.fqtest | 2 +- format/luajit/testdata/simple_stripped.fqtest | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/format/luajit/luajit.go b/format/luajit/luajit.go index b9983f59..0efc263f 100644 --- a/format/luajit/luajit.go +++ b/format/luajit/luajit.go @@ -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") diff --git a/format/luajit/testdata/simple.fqtest b/format/luajit/testdata/simple.fqtest index 85e2b6c0..1537d90a 100644 --- a/format/luajit/testdata/simple.fqtest +++ b/format/luajit/testdata/simple.fqtest @@ -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) diff --git a/format/luajit/testdata/simple_stripped.fqtest b/format/luajit/testdata/simple_stripped.fqtest index 1f09d5eb..4226fdce 100644 --- a/format/luajit/testdata/simple_stripped.fqtest +++ b/format/luajit/testdata/simple_stripped.fqtest @@ -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)