Closed dhowden closed 4 years ago
Just found a DSF file that's over 2GB and fails. Not yet applied these changes, will try
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)
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.