Skip to content

Commit aed553b

Browse files
committed
#468 WAV files with RIFF and data chunk sizes of zero
#468 Attempt to guess appropriate values for RIFF and RIFF.data size fields when fields are zero.
1 parent 4b9ba2c commit aed553b

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

getid3/getid3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ class getID3
387387
*/
388388
protected $startup_warning = '';
389389

390-
const VERSION = '1.9.23-202502021530';
390+
const VERSION = '1.9.23-202509032051';
391391
const FREAD_BUFFER_SIZE = 32768;
392392

393393
const ATTACHMENTS_NONE = false;

getid3/module.audio-video.riff.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,19 @@ public function Analyze() {
6767
$RIFFsize = substr($RIFFheader, 4, 4);
6868
$RIFFsubtype = substr($RIFFheader, 8, 4);
6969

70-
switch ($RIFFtype) {
70+
if ($RIFFsize == "\x00\x00\x00\x00") {
71+
// https://github.com/JamesHeinrich/getID3/issues/468
72+
// may occur in streaming files where the data size is unknown
73+
$thisfile_riff['header_size'] = $info['avdataend'] - 8;
74+
$this->warning('RIFF size field is empty, assuming the correct value is filesize-8 ('.$thisfile_riff['header_size'].')');
75+
} else {
76+
$thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize);
77+
}
7178

79+
switch ($RIFFtype) {
7280
case 'FORM': // AIFF, AIFC
7381
//$info['fileformat'] = 'aiff';
7482
$this->container = 'aiff';
75-
$thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize);
7683
$thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4));
7784
break;
7885

@@ -81,7 +88,6 @@ public function Analyze() {
8188
case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s
8289
//$info['fileformat'] = 'riff';
8390
$this->container = 'riff';
84-
$thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize);
8591
if ($RIFFsubtype == 'RMP3') {
8692
// RMP3 is identical to WAVE, just renamed. Used by [unknown program] when creating RIFF-MP3s
8793
$RIFFsubtype = 'WAVE';
@@ -1606,9 +1612,18 @@ public function ParseRIFF($startoffset, $maxoffset) {
16061612
$this->error('Expecting chunk name at offset '.($this->ftell() - 8).' but found nothing. Aborting RIFF parsing.');
16071613
break;
16081614
}
1609-
if (($chunksize == 0) && ($chunkname != 'JUNK')) {
1610-
$this->warning('Chunk ('.$chunkname.') size at offset '.($this->ftell() - 4).' is zero. Aborting RIFF parsing.');
1611-
break;
1615+
if ($chunksize == 0) {
1616+
if ($chunkname == 'JUNK') {
1617+
// this is allowed
1618+
} elseif ($chunkname == 'data') {
1619+
// https://github.com/JamesHeinrich/getID3/issues/468
1620+
// may occur in streaming files where the data size is unknown
1621+
$chunksize = $info['avdataend'] - $this->ftell();
1622+
$this->warning('RIFF.data size field is empty, assuming the correct value is filesize-offset ('.$chunksize.')');
1623+
} else {
1624+
$this->warning('Chunk ('.$chunkname.') size at offset '.($this->ftell() - 4).' is zero. Aborting RIFF parsing.');
1625+
break;
1626+
}
16121627
}
16131628
if (($chunksize % 2) != 0) {
16141629
// all structures are packed on word boundaries

0 commit comments

Comments
 (0)