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

test[fuzz]: fix issue where section data offset > end #4

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

actuallyachraf
Copy link
Contributor

@actuallyachraf actuallyachraf commented Mar 14, 2021

This PR fixes issues triggered by fuzzing (incomplete)

@@ -144,6 +144,9 @@ type ResourceDataEntry struct {
}

// makeIntResource mimics the MAKEINTRESOURCE macro.
// go-vet : tagged as misues of unsafe.Pointer (
// go test -gcflags=all=-d=checkptr
// fatal error: checkptr: pointer arithmetic computed bad pointer value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.

if (pe.Is32 && oh32.SizeOfImage%oh32.SectionAlignment != 0) ||
(pe.Is64 && oh64.SizeOfImage%oh64.SectionAlignment != 0) {
pe.Anomalies = append(pe.Anomalies, AnoInvalidSizeOfImage)
// Check that SectionAlignment is not 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch +1

@@ -349,6 +349,12 @@ type DataDirectory struct {
// beginning of the file.
func (pe *File) ParseNTHeader() (err error) {
ntHeaderOffset := pe.DosHeader.AddressOfNewEXEHeader
// LittleEndian.Uint32 will panic if input doesn't have enough bytes (index out of range)
// in the case where pe.data[ntHeaderOffset:] is less than 4 bytes
signatureBytes := pe.data[ntHeaderOffset:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot this one, we have a helper function that should be used here:

// ReadUint32 read a uint32 from a buffer.
func (pe *File) ReadUint32(offset uint32) (uint32, error) {
	if offset+4 > pe.size {
		return 0, ErrOutsideBoundary
	}

	return binary.LittleEndian.Uint32(pe.data[offset:]), nil
}

// Something like this:
signature, err := pe.ReadUint32(ntHeaderOffset)
if err != nil {
    return ErrInvalidNTHeaderOffset
}

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

Successfully merging this pull request may close these issues.

Integer divide by zero when checking against section alignment anomaly
2 participants