From 193f23a20c9d5b2fe985d6c0180ea40c2448964e Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Fri, 13 Jun 2025 20:40:34 +0200 Subject: [PATCH] Add error handling for processChunks --- fmp/fmp_file.go | 6 +++++- fmp/fmp_sector.go | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/fmp/fmp_file.go b/fmp/fmp_file.go index e4344ac..71441eb 100644 --- a/fmp/fmp_file.go +++ b/fmp/fmp_file.go @@ -52,8 +52,12 @@ func OpenFile(path string) (*FmpFile, error) { } ctx.Sectors = append(ctx.Sectors, sector) + if sector.ID != 0 { - sector.processChunks(ctx.Dictionary, ¤tPath) + err = sector.processChunks(ctx.Dictionary, ¤tPath) + if err != nil { + return nil, err + } ctx.Chunks = append(ctx.Chunks, sector.Chunks...) } diff --git a/fmp/fmp_sector.go b/fmp/fmp_sector.go index ec39a88..bc7d895 100644 --- a/fmp/fmp_sector.go +++ b/fmp/fmp_sector.go @@ -10,7 +10,7 @@ func (sect *FmpSector) readChunks() error { panic("chunks already read") } for { - pos := (sect.ID+2)*sectorSize - uint64(len(sect.Payload)) + pos := sect.ID*sectorSize - uint64(len(sect.Payload)) chunk, err := sect.readChunk(sect.Payload) if chunk == nil { @@ -46,8 +46,12 @@ func (sect *FmpSector) readChunks() error { return nil } -func (sect *FmpSector) processChunks(dict *FmpDict, currentPath *[]uint64) { - sect.readChunks() +func (sect *FmpSector) processChunks(dict *FmpDict, currentPath *[]uint64) error { + err := sect.readChunks() + if err != nil { + return err + } + for _, chunk := range sect.Chunks { switch chunk.Type { case FMP_CHUNK_PATH_PUSH: @@ -92,6 +96,7 @@ func (sect *FmpSector) processChunks(dict *FmpDict, currentPath *[]uint64) { } } } + return nil } func (sect *FmpSector) readChunk(payload []byte) (*FmpChunk, error) {