Skip to content

Commit

Permalink
Merge pull request #141 from tri-adam/fix-padding-v1
Browse files Browse the repository at this point in the history
Fix Inconsistent Alignment Accounting for Data Objects (v1)
  • Loading branch information
tri-adam authored Sep 9, 2021
2 parents 9af8c2f + b8aa7fd commit 26f00a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 5 additions & 4 deletions pkg/sif/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ func writeDescriptors(fimg *FileImage) error {
return fmt.Errorf("binary writing descrtable to buf: %s", err)
}
}
fimg.Header.Descrlen = int64(binary.Size(fimg.DescrArr))

return nil
}
Expand Down Expand Up @@ -225,6 +224,7 @@ func writeHeader(fimg *FileImage) error {
func CreateContainer(cinfo CreateInfo) (fimg *FileImage, err error) {
fimg = &FileImage{}
fimg.DescrArr = make([]Descriptor, DescrNumEntries)
descrLen := int64(binary.Size(fimg.DescrArr))

// Prepare a fresh global header
copy(fimg.Header.Launch[:], cinfo.Launchstr)
Expand All @@ -237,7 +237,8 @@ func CreateContainer(cinfo CreateInfo) (fimg *FileImage, err error) {
fimg.Header.Dfree = DescrNumEntries
fimg.Header.Dtotal = DescrNumEntries
fimg.Header.Descroff = DescrStartOffset
fimg.Header.Dataoff = DataStartOffset
fimg.Header.Descrlen = descrLen
fimg.Header.Dataoff = DescrStartOffset + descrLen

// Create container file
fimg.Fp, err = os.OpenFile(cinfo.Pathname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o755)
Expand All @@ -251,8 +252,8 @@ func CreateContainer(cinfo CreateInfo) (fimg *FileImage, err error) {
}()

// set file pointer to start of data section */
if _, err = fimg.Fp.Seek(DataStartOffset, 0); err != nil {
return nil, fmt.Errorf("setting file offset pointer to DataStartOffset: %s", err)
if _, err = fimg.Fp.Seek(fimg.Header.Dataoff, 0); err != nil {
return nil, fmt.Errorf("setting file offset pointer to Dataoff: %s", err)
}

for _, v := range cinfo.InputDescr {
Expand Down
7 changes: 6 additions & 1 deletion pkg/sif/sif.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ const (
DescrNameLen = 128 // descriptor name (string identifier)
DescrMaxPrivLen = 384 // size reserved for descriptor specific data
DescrStartOffset = 4096 // where descriptors start after global header
DataStartOffset = 32768 // where data object start after descriptors
)

// DataStartOffset indicates where data object start after descriptors.
//
// Deprecated: this value may not be accurate for all images. Use (Header).Dataoff from the image
// instead.
const DataStartOffset = 32768

// Datatype represents the different SIF data object types stored in the image.
type Datatype int32

Expand Down

0 comments on commit 26f00a3

Please sign in to comment.