dhowden / tag

ID3, MP4 and OGG/FLAC metadata parsing in Go
BSD 2-Clause "Simplified" License
558 stars 72 forks source link

move towards using uint for all sizes #59

Closed dhowden closed 4 years ago

dhowden commented 4 years ago

Quickly knocked this together. We could do with more testing, and probably some fuzzing also!

Doubt I will have time to do anything further until the weekend, so feel free to test this and suggest improvements/changes!

At the moment we're just aiming to switch to using unsigned integers.

pgalbavy commented 4 years ago

Just found a DSF file that's over 2GB and fails. Not yet applied these changes, will try

pgalbavy commented 4 years ago

I found it needs a getUintLittleEndian() to fix - but this still limits us to 4GB as the point is a 64 bit value. Should I create a new issue for 64 bit values overall or let it sit with this?

quick fix:

diff --git a/dsf.go b/dsf.go
index 47e0510..040bed6 100644
--- a/dsf.go
+++ b/dsf.go
@@ -30,7 +30,7 @@ func ReadDSFTags(r io.ReadSeeker) (Metadata, error) {
        if err != nil {
                return nil, err
        }
-       id3Pointer := getIntLittleEndian(n4)
+       id3Pointer := getUintLittleEndian(n4)

        f, err := readString(r, 4)
        if err != nil {
diff --git a/util.go b/util.go
index 60ff59f..3df809b 100644
--- a/util.go
+++ b/util.go
@@ -50,6 +50,15 @@ func getIntLittleEndian(b []byte) int {
        return n
 }

+func getUintLittleEndian(b []byte) uint {
+       var n uint
+       for i := len(b) - 1; i >= 0; i-- {
+               n = n << 8
+               n |= uint(b[i])
+       }
+       return n
+}
+
 func readBytes(r io.Reader, n int) ([]byte, error) {
        b := make([]byte, n)
        _, err := io.ReadFull(r, b)