[xiph-commits] r7484 - trunk/vorbisfile-python

jack at motherfish-iii.xiph.org jack
Thu Aug 5 19:11:20 PDT 2004


Author: jack
Date: Thu Aug  5 19:11:20 2004
New Revision: 7484

Modified:
trunk/vorbisfile-python/vorbisfile.c
trunk/vorbisfile-python/vorbisfile.py
Log:
Fix a bug where the negative return from ov_read would cause a random
length string to be returned.


Modified: trunk/vorbisfile-python/vorbisfile.c
===================================================================
--- trunk/vorbisfile-python/vorbisfile.c	2004-08-05 13:53:16 UTC (rev 7483)
+++ trunk/vorbisfile-python/vorbisfile.c	2004-08-05 14:28:41 UTC (rev 7484)
@@ -850,10 +850,12 @@
buffer = (char *)PyMem_Malloc(len);
vf = (OggVorbis_File *)PyCObject_AsVoidPtr(cobj);
ret = ov_read(vf, buffer, len, bigendianp, word, sgned, &current_section);
-    if (ret > 0)
-	buffer = (char *)PyMem_Realloc(buffer, ret);
-
-    result = Py_BuildValue("(ls#i)", ret, buffer, ret, current_section);
+    if (ret >= 0) {
+	result = Py_BuildValue("(ls#i)", ret, buffer, ret, current_section);
+    } else {
+	result = Py_BuildValue("(ls#i)", ret, buffer, 0, current_section);
+    }
+    PyMem_Free(buffer);
return result;
}


Modified: trunk/vorbisfile-python/vorbisfile.py
===================================================================
--- trunk/vorbisfile-python/vorbisfile.py	2004-08-05 13:53:16 UTC (rev 7483)
+++ trunk/vorbisfile-python/vorbisfile.py	2004-08-05 14:28:41 UTC (rev 7484)
@@ -10,6 +10,9 @@
FORMAT_INT = 0
FORMAT_FLOAT = 1

+class VorbisFileHoleError(StandardError):
+    pass
+
class VorbisFile(object):
def __init__(self):
self.vf = None
@@ -116,6 +119,8 @@
real_num = num * wordsize * 2 # FIXME: get number channels
samps, data, cs = ov_read(self.vf, real_num, bendian,
wordsize, signed)
+            if samps < 0:
+                raise VorbisFileHoleError, "vorbisfile error %d" % samps
return data, cs
else:
raise StandardError, "Unknown format requested"



More information about the commits mailing list