packed: switch gogo/proto → google
This commit is contained in:
parent
b32ba090a2
commit
357f702925
5 changed files with 345 additions and 1113 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue