feat(parser): linux-generic content-driven parser and RAR archive support
Field bundles from ad-hoc service scripts (first sample: Giga G894-SD3 .rar with dmidecode/lscpu/lspci/nvme/lsblk output, no fixed layout). ADL-078: - linux-generic: recognizes utility output by content, merges records by stable key, low detect confidence (20-30) below all vendor parsers - pciids.LookupByDescription: resolve a textual lspci description back to vendor/device IDs and manufacturer/model - archive: accept .rar via the in-repo internal/rar5 reader (RAR 5 / RAR 7, single volume, solid; encrypted, multi-volume, SFX and RAR 4.x rejected), same per-file and total limits as tar/zip - UI: .rar in the upload accept list Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ff5b99fa5c
commit
b4b15e58a2
25 files changed
+4901
-5
No files matched your search
@@ -0,0 +1,65 @@
|
||||
// Derived from github.com/nwaples/rardecode (BSD 2-Clause), see LICENSE.
|
||||
|
||||
package rar5
|
||||
|
||||
import "io"
|
||||
|
||||
// bitReader reads bits from the packed data of one file and stops with
|
||||
// io.EOF once the bit limit of the current compressed block is reached.
|
||||
type bitReader struct {
|
||||
r io.ByteReader
|
||||
v int // cache of bits read from r
|
||||
l int // number of bits (not cached) that can still be read from r
|
||||
n uint8 // number of unread bits in v
|
||||
}
|
||||
|
||||
func (r *bitReader) reset(br io.ByteReader) {
|
||||
r.r = br
|
||||
r.v, r.l, r.n = 0, 0, 0
|
||||
}
|
||||
|
||||
func (r *bitReader) unreadBits(n uint8) { r.n += n }
|
||||
|
||||
// readByte reads a whole byte; block headers are byte-aligned.
|
||||
func (r *bitReader) readByte() (byte, error) {
|
||||
if r.n == 0 {
|
||||
return r.r.ReadByte()
|
||||
}
|
||||
b, err := r.readBits(8)
|
||||
return byte(b), err
|
||||
}
|
||||
|
||||
// setLimit sets the number of bits the current block holds.
|
||||
func (r *bitReader) setLimit(n int) {
|
||||
r.l = n
|
||||
r.n = 0
|
||||
}
|
||||
|
||||
// readBits returns n bits. n must be less than the integer size - 8.
|
||||
func (r *bitReader) readBits(n uint8) (int, error) {
|
||||
for n > r.n {
|
||||
if r.l == 0 {
|
||||
// reached the block's bit limit
|
||||
return 0, io.EOF
|
||||
}
|
||||
c, err := r.r.ReadByte()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
err = ErrCorrupt
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
r.v = r.v<<8 | int(c)
|
||||
r.n += 8
|
||||
r.l -= 8
|
||||
if r.l < 0 {
|
||||
// overshot, discard the extra bits
|
||||
bits := uint8(-r.l)
|
||||
r.l = 0
|
||||
r.v >>= bits
|
||||
r.n -= bits
|
||||
}
|
||||
}
|
||||
r.n -= n
|
||||
return (r.v >> r.n) & ((1 << n) - 1), nil
|
||||
}
|
||||
Reference in new issue
Block a user