From c87204c78a1974aaf3496d961d4d43bec8c28738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Thu, 12 Sep 2024 15:08:04 +0100 Subject: [PATCH] fix #96: ncm file parsing when image cover 2 is not empty --- algo/ncm/ncm.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/algo/ncm/ncm.go b/algo/ncm/ncm.go index afa572f..5c35f77 100644 --- a/algo/ncm/ncm.go +++ b/algo/ncm/ncm.go @@ -149,12 +149,18 @@ func (d *Decoder) readMetaData() error { } func (d *Decoder) readCoverData() error { - bCoverCRC := make([]byte, 4) - if _, err := io.ReadFull(d.rd, bCoverCRC); err != nil { - return fmt.Errorf("ncm read cover crc: %w", err) + bCoverFrameLen := make([]byte, 4) + if _, err := io.ReadFull(d.rd, bCoverFrameLen); err != nil { + return fmt.Errorf("ncm read cover length: %w", err) + } + + coverFrameStartOffset, err := d.rd.Seek(0, io.SeekCurrent) + if err != nil { + return fmt.Errorf("ncm fetch cover frame start offset: %w", err) } + coverFrameLen := binary.LittleEndian.Uint32(bCoverFrameLen) - bCoverLen := make([]byte, 4) // + bCoverLen := make([]byte, 4) if _, err := io.ReadFull(d.rd, bCoverLen); err != nil { return fmt.Errorf("ncm read cover length: %w", err) } @@ -166,7 +172,10 @@ func (d *Decoder) readCoverData() error { } d.cover = coverBuf - return nil + offsetAudioData := coverFrameStartOffset + int64(coverFrameLen) + 4 + _, err = d.rd.Seek(offsetAudioData, io.SeekStart) + + return err } func (d *Decoder) parseMeta() error {