From b134e99fff471837157550dc8c479e65b4ca2b03 Mon Sep 17 00:00:00 2001 From: Kubo Ryosuke Date: Tue, 16 Jan 2024 20:29:30 +0900 Subject: [PATCH 1/2] Fix for code scanning --- field.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/field.go b/field.go index 585833e..b43833e 100644 --- a/field.go +++ b/field.go @@ -2,6 +2,7 @@ package mp4 import ( "fmt" + "math" "os" "reflect" "sort" @@ -179,6 +180,9 @@ func buildField(fieldName string, tag string) *field { if err != nil { panic(err) } + if ver > math.MaxUint8 { + panic("ver-tag must be <=255") + } f.version = uint8(ver) } @@ -188,6 +192,9 @@ func buildField(fieldName string, tag string) *field { if err != nil { panic(err) } + if ver > math.MaxUint8 { + panic("nver-tag must be <=255") + } f.nVersion = uint8(ver) } From ba4604062802d84d8b81c91adcee0e856452d5a6 Mon Sep 17 00:00:00 2001 From: Kubo Ryosuke Date: Tue, 16 Jan 2024 20:30:47 +0900 Subject: [PATCH 2/2] Fix for lint --- box_info_test.go | 3 +-- cmd/mp4tool/internal/dump/dump_test.go | 4 ++-- cmd/mp4tool/internal/extract/extract_test.go | 4 ++-- cmd/mp4tool/internal/probe/probe_test.go | 4 ++-- cmd/mp4tool/internal/psshdump/psshdump_test.go | 4 ++-- marshaller.go | 12 +++--------- read.go | 2 +- write_test.go | 3 +-- 8 files changed, 14 insertions(+), 22 deletions(-) diff --git a/box_info_test.go b/box_info_test.go index 792024b..423f030 100644 --- a/box_info_test.go +++ b/box_info_test.go @@ -3,7 +3,6 @@ package mp4 import ( "bytes" "io" - "io/ioutil" "testing" "github.com/orcaman/writerseeker" @@ -108,7 +107,7 @@ func TestWriteBoxInfo(t *testing.T) { if !c.hasError { require.NoError(t, err) assert.Equal(t, c.expectedBI, bi) - b, err := ioutil.ReadAll(w.Reader()) + b, err := io.ReadAll(w.Reader()) require.NoError(t, err) assert.Equal(t, c.expectedBytes, b) } else { diff --git a/cmd/mp4tool/internal/dump/dump_test.go b/cmd/mp4tool/internal/dump/dump_test.go index 8f1e592..150d2ad 100644 --- a/cmd/mp4tool/internal/dump/dump_test.go +++ b/cmd/mp4tool/internal/dump/dump_test.go @@ -1,7 +1,7 @@ package dump import ( - "io/ioutil" + "io" "os" "testing" @@ -51,7 +51,7 @@ func TestDump(t *testing.T) { os.Stdout = w Main(append(tc.options, tc.file)) w.Close() - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) require.NoError(t, err) assert.Equal(t, tc.wants, string(b)) }) diff --git a/cmd/mp4tool/internal/extract/extract_test.go b/cmd/mp4tool/internal/extract/extract_test.go index 15a7f71..45f9614 100644 --- a/cmd/mp4tool/internal/extract/extract_test.go +++ b/cmd/mp4tool/internal/extract/extract_test.go @@ -1,7 +1,7 @@ package extract import ( - "io/ioutil" + "io" "os" "testing" @@ -46,7 +46,7 @@ func TestExtract(t *testing.T) { os.Stdout = w require.Zero(t, Main([]string{tc.boxType, tc.file})) w.Close() - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) require.NoError(t, err) assert.Equal(t, tc.expectedSize, len(b)) assert.Equal(t, tc.boxType, string(b[4:8])) diff --git a/cmd/mp4tool/internal/probe/probe_test.go b/cmd/mp4tool/internal/probe/probe_test.go index f98fc61..8925b14 100644 --- a/cmd/mp4tool/internal/probe/probe_test.go +++ b/cmd/mp4tool/internal/probe/probe_test.go @@ -1,7 +1,7 @@ package probe import ( - "io/ioutil" + "io" "os" "testing" @@ -44,7 +44,7 @@ func TestProbe(t *testing.T) { os.Stdout = w Main(append(tc.options, tc.file)) w.Close() - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) require.NoError(t, err) assert.Equal(t, tc.wants, string(b)) } diff --git a/cmd/mp4tool/internal/psshdump/psshdump_test.go b/cmd/mp4tool/internal/psshdump/psshdump_test.go index e350135..4735437 100644 --- a/cmd/mp4tool/internal/psshdump/psshdump_test.go +++ b/cmd/mp4tool/internal/psshdump/psshdump_test.go @@ -1,7 +1,7 @@ package psshdump import ( - "io/ioutil" + "io" "os" "testing" @@ -54,7 +54,7 @@ func TestPsshdump(t *testing.T) { os.Stdout = w Main(append(tc.options, tc.file)) w.Close() - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) require.NoError(t, err) assert.Equal(t, tc.wants, string(b)) }) diff --git a/marshaller.go b/marshaller.go index ff6c64c..b8a0f38 100644 --- a/marshaller.go +++ b/marshaller.go @@ -33,11 +33,7 @@ func readerHasSize(reader bitio.ReadSeeker, size uint64) bool { } _, err = reader.Seek(pre, io.SeekStart) - if err != nil { - return false - } - - return true + return err == nil } type marshaller struct { @@ -128,8 +124,7 @@ func (m *marshaller) marshalStruct(v reflect.Value, fs []*field) error { func (m *marshaller) marshalArray(v reflect.Value, fi *fieldInstance) error { size := v.Type().Size() for i := 0; i < int(size)/int(v.Type().Elem().Size()); i++ { - var err error - err = m.marshal(v.Index(i), fi) + err := m.marshal(v.Index(i), fi) if err != nil { return err } @@ -414,8 +409,7 @@ func (u *unmarshaller) unmarshalStruct(v reflect.Value, fs []*field) error { func (u *unmarshaller) unmarshalArray(v reflect.Value, fi *fieldInstance) error { size := v.Type().Size() for i := 0; i < int(size)/int(v.Type().Elem().Size()); i++ { - var err error - err = u.unmarshal(v.Index(i), fi) + err := u.unmarshal(v.Index(i), fi) if err != nil { return err } diff --git a/read.go b/read.go index 7118d80..475739a 100644 --- a/read.go +++ b/read.go @@ -192,7 +192,7 @@ func readBoxStructure(r io.ReadSeeker, totalSize uint64, isRoot bool, path BoxPa } if totalSize != 0 && !ctx.IsQuickTimeCompatible { - return nil, errors.New("Unexpected EOF") + return nil, errors.New("unexpected EOF") } return vals, nil diff --git a/write_test.go b/write_test.go index 5b1f785..7dc4616 100644 --- a/write_test.go +++ b/write_test.go @@ -3,7 +3,6 @@ package mp4 import ( "bytes" "io" - "io/ioutil" "testing" "gopkg.in/src-d/go-billy.v4/memfs" @@ -110,7 +109,7 @@ func TestWriter(t *testing.T) { _, err = output.Seek(0, io.SeekStart) require.NoError(t, err) - bin, err := ioutil.ReadAll(output) + bin, err := io.ReadAll(output) require.NoError(t, err) assert.Equal(t, []byte{ // ftyp