From dd6c6bd44265cf29f17d3f8c1ff03de02ecab27c Mon Sep 17 00:00:00 2001 From: "Greg T. Wallace" Date: Sat, 27 Jan 2024 11:35:36 -0500 Subject: [PATCH] header: fix (needed proper type conversion) --- pkg/app/file_header.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/app/file_header.go b/pkg/app/file_header.go index b3f365a..0a40e15 100644 --- a/pkg/app/file_header.go +++ b/pkg/app/file_header.go @@ -58,17 +58,18 @@ func makeFileHeader(p15File []byte) ([]byte, error) { // check sums (CRC Table) checksumTable := crc16.MakeTable(crc16.CRC16_XMODEM) + // NOTE: 16 bit checksums are moved to 32 bit int with sign-extension by converting + // to int16 and then to uint32 + // file checksum fileChecksum := make([]byte, 4) - binary.LittleEndian.PutUint16(fileChecksum, crc16.Checksum(p15File, checksumTable)) + binary.LittleEndian.PutUint32(fileChecksum, uint32(int16(crc16.Checksum(p15File, checksumTable)))) copy(header[220:], fileChecksum) // header checksum headerChecksum := make([]byte, 4) - binary.LittleEndian.PutUint16(headerChecksum, crc16.Checksum(header[:224], checksumTable)) + binary.LittleEndian.PutUint32(headerChecksum, uint32(int16(crc16.Checksum(header[:224], checksumTable)))) copy(header[224:], headerChecksum) - // this was in original code but - return header, nil }