packed: switch gogo/proto → google

This commit is contained in:
Laurence Withers 2026-06-06 11:00:04 +01:00
commit 351d279a22
5 changed files with 345 additions and 1111 deletions

View file

@ -8,6 +8,7 @@ import (
"strings"
"golang.org/x/sys/unix"
"google.golang.org/protobuf/proto"
)
const (
@ -130,7 +131,7 @@ func Load(f *os.File) (*Header, *Directory, error) {
// as type LoadError.
func readHeader(f []byte) (*Header, error) {
hdr := new(Header)
if err := hdr.Unmarshal(f[:36]); err != nil {
if err := proto.Unmarshal(f[:36], hdr); err != nil {
return nil, &LoadError{
Cause: HeaderUnmarshalError,
Underlying: err,
@ -166,15 +167,17 @@ func readHeader(f []byte) (*Header, error) {
// read/checksummed).
func readDirectory(f []byte, hdr *Header) (*Directory, error) {
fileSize := uint64(len(f))
start := hdr.DirectoryOffset
end := start + hdr.DirectoryLength
if hdr.DirectoryOffset+hdr.DirectoryLength > fileSize {
if end > fileSize {
return nil, &LoadError{
Cause: BadOffsetError,
}
}
dir := new(Directory)
if err := dir.Unmarshal(f[hdr.DirectoryOffset : hdr.DirectoryOffset+hdr.DirectoryLength]); err != nil {
if err := proto.Unmarshal(f[start:end], dir); err != nil {
return nil, &LoadError{
Cause: DirectoryUnmarshalError,
Underlying: err,