changeset 15530:203c78063bff

Fix wavread to support truncated files (bug #37532) * wavread.m: Limit chunk sizes by the total size of the input file.
author Mike Miller <mtmiller@ieee.org>
date Mon, 15 Oct 2012 21:44:52 -0400
parents 9a7f73fc304f
children 39fd2ad26fb7
files scripts/audio/wavread.m
diffstat 1 files changed, 2 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/audio/wavread.m	Mon Oct 15 21:02:42 2012 -0400
+++ b/scripts/audio/wavread.m	Mon Oct 15 21:44:52 2012 -0400
@@ -76,6 +76,7 @@
     if (riff_size == -1)
       error ("wavread: file contains no RIFF chunk");
     endif
+    riff_size = min (riff_size, file_size - riff_pos);
 
     riff_type = char (fread (fid, 4))';
     if (! strcmp (riff_type, "WAVE"))
@@ -100,6 +101,7 @@
     if (data_size == -1)
       error ("wavread: file contains no data chunk");
     endif
+    data_size = min (data_size, file_size - data_pos);
 
     ### Read format chunk.
     fseek (fid, fmt_pos, "bof");