Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect ArchiveHeader.Data size #14

Open
pagran opened this issue Oct 19, 2020 · 1 comment
Open

Incorrect ArchiveHeader.Data size #14

pagran opened this issue Oct 19, 2020 · 1 comment

Comments

@pagran
Copy link

pagran commented Oct 19, 2020

After parsing an object file, I get an invalid ArchiveHeader.Data field with garbage at the end. The ArchiveHeader.Size field is also set incorrectly.

Code:

package main

import (
	"fmt"
	"github.com/Binject/debug/goobj2"
)

func main() {
	const magicHeaderName = "magic/example"

	magicData := make([]byte, 256)

	original, err := goobj2.Parse("a.obj", "main", nil)
	if err != nil {
		panic(err)
	}

	original.ArchiveMembers = append(original.ArchiveMembers, goobj2.ArchiveMember{
		ArchiveHeader: goobj2.ArchiveHeader{
			Name: magicHeaderName,
			Size: int64(len(magicData)),
			Data: magicData,
		},
	})

	if err := original.Write("b.obj"); err != nil {
		panic(err)
	}

	patched, err := goobj2.Parse("b.obj", "main", nil)
	if err != nil {
		panic(err)
	}

	var magicArchive goobj2.ArchiveMember
	for _, member := range patched.ArchiveMembers {
		if member.ArchiveHeader.Name == magicHeaderName {
			magicArchive = member
			break
		}
	}

	if magicArchive.ArchiveHeader.Size != int64(len(magicData)) {
		panic(fmt.Sprintf("real size %d != parsed size %d", magicArchive.ArchiveHeader.Size, len(magicData)))
	}
}

Output:

panic: real size 348 != parsed size 256
@pagran
Copy link
Author

pagran commented Oct 23, 2020

IsDataObj generates incorrect object files. I add IsDataObj=true here and get error "corrupt archive": https://github.com/Binject/debug/blob/master/goobj2/file.go#L509

Object file: pkg.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants