From 27494be1631ea765f277c7a14467e7f46403c3d9 Mon Sep 17 00:00:00 2001 From: svollbehr Date: Sat, 30 Apr 2011 10:37:09 +0000 Subject: [PATCH] Fix issue 41 git-svn-id: http://php-reader.googlecode.com/svn/trunk@215 51a70ab9-7547-0410-9469-37e369ee0574 --- src/Zend/Media/Id3/Frame.php | 5 +++-- src/Zend/Media/Id3/Frame/Apic.php | 2 +- src/Zend/Media/Id3/Header.php | 16 ++++++++-------- src/Zend/Media/Id3/Object.php | 29 +++++++---------------------- 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/Zend/Media/Id3/Frame.php b/src/Zend/Media/Id3/Frame.php index f6fd4d6..96753da 100644 --- a/src/Zend/Media/Id3/Frame.php +++ b/src/Zend/Media/Id3/Frame.php @@ -314,12 +314,13 @@ abstract class Zend_Media_Id3_Frame extends Zend_Media_Id3_Object } $writer->writeString8(substr($this->_identifier, 0, 4), 4, " ") - ->writeUInt32BE($this->_encodeSynchsafe32($size)) + ->writeUInt32BE($this->getOption('version', 4) < 4 ? $size : $this->_encodeSynchsafe32($size)) ->writeUInt16BE($flags); if (($flags & self::DATA_LENGTH_INDICATOR) == self::DATA_LENGTH_INDICATOR) { - $writer->writeUInt32BE($this->_encodeSynchsafe32($this->_size)); + $writer->writeUInt32BE + ($this->getOption('version', 4) < 4 ? $this->_size : $this->_encodeSynchsafe32($this->_size)); } $writer->write($data); } diff --git a/src/Zend/Media/Id3/Frame/Apic.php b/src/Zend/Media/Id3/Frame/Apic.php index 3fc4f24..1a6a4eb 100644 --- a/src/Zend/Media/Id3/Frame/Apic.php +++ b/src/Zend/Media/Id3/Frame/Apic.php @@ -285,6 +285,6 @@ final class Zend_Media_Id3_Frame_Apic extends Zend_Media_Id3_Frame $writer->writeString8($this->_description, 1); break; } - $writer->writeString8($this->_imageData); + $writer->write($this->_imageData); } } diff --git a/src/Zend/Media/Id3/Header.php b/src/Zend/Media/Id3/Header.php index 804232d..1a54498 100644 --- a/src/Zend/Media/Id3/Header.php +++ b/src/Zend/Media/Id3/Header.php @@ -81,10 +81,10 @@ final class Zend_Media_Id3_Header extends Zend_Media_Id3_Object return; $this->_version = $options['version'] = - $this->_reader->readInt8() + $this->_reader->readInt8() / 10; - $this->_flags = $this->_reader->readInt8(); - $this->_size = - $this->_decodeSynchsafe32($this->_reader->readUInt32BE()); + $this->_reader->readUInt8() + $this->_reader->readUInt8() / 10; + $this->_flags = $this->_reader->readUInt8(); + $this->_size = $this->_version < 4 ? + $this->_reader->readUInt32BE() : $this->_decodeSynchsafe32($this->_reader->readUInt32BE()); } /** @@ -171,9 +171,9 @@ final class Zend_Media_Id3_Header extends Zend_Media_Id3_Object */ public function write($writer) { - $writer->writeInt8(floor($this->_version)) - ->writeInt8(($this->_version - floor($this->_version)) * 10) - ->writeInt8($this->_flags) - ->writeUInt32BE($this->_encodeSynchsafe32($this->_size)); + $writer->writeUInt8(floor($this->_version)) + ->writeUInt8(($this->_version - floor($this->_version)) * 10) + ->writeUInt8($this->_flags) + ->writeUInt32BE($this->_version < 4 ? $this->_size : $this->_encodeSynchsafe32($this->_size)); } } diff --git a/src/Zend/Media/Id3/Object.php b/src/Zend/Media/Id3/Object.php index 1cacca2..32cd5db 100644 --- a/src/Zend/Media/Id3/Object.php +++ b/src/Zend/Media/Id3/Object.php @@ -172,7 +172,6 @@ abstract class Zend_Media_Id3_Object /** * Decodes the given 28-bit synchsafe integer to regular 32-bit integer. * - * @param integer $val The integer to decode * @return integer */ @@ -188,24 +187,17 @@ abstract class Zend_Media_Id3_Object * Whenever a false synchronisation is found within the data, one zeroed * byte is inserted after the first false synchronisation byte. This has the * side effect that all 0xff00 combinations have to be altered, so they will - * not be affected by the decoding process. Therefore all the 0xff00 - * combinations have to be replaced with the 0xff0000 combination during the - * unsynchronisation. + * not be affected by the decoding process. + * + * Therefore all the 0xff00 combinations are replaced with the 0xff0000 combination and all the 0xff[0xe0-0xff] + * combinations are replaced with 0xff00[0xe0-0xff] during the unsynchronisation. * * @param string $data The input data. * @return string */ protected final function _encodeUnsynchronisation(&$data) { - $result = ''; - for ($i = 0, $j = 0; $i < strlen($data) - 1; $i++) { - if (ord($data[$i]) == 0xff && - ((($tmp = ord($data[$i + 1])) & 0xe0) == 0xe0 || $tmp == 0x0)) { - $result .= substr($data, $j, $i + 1 - $j) . "\0"; - $j = $i + 1; - } - } - return $result . substr($data, $j); + return preg_replace('/\xff(?=[\xe0-\xff])/', "\xff\x00", preg_replace('/\xff\x00/', "\xff\x00\x00", $data)); } /** @@ -217,14 +209,7 @@ abstract class Zend_Media_Id3_Object */ protected final function _decodeUnsynchronisation(&$data) { - $result = ''; - for ($i = 0, $j = 0; $i < strlen($data) - 1; $i++) { - if (ord($data[$i]) == 0xff && ord($data[$i + 1]) == 0x0) { - $result .= substr($data, $j, $i + 1 - $j); - $j = $i + 2; - } - } - return $result . substr($data, $j); + return preg_replace('/\xff\x00\x00/', "\xff\x00", preg_replace('/\xff\x00(?=[\xe0-\xff])/', "\xff", $data)); } /** @@ -263,7 +248,7 @@ abstract class Zend_Media_Id3_Object */ protected final function _explodeString8($value, $limit = null) { - return preg_split("/\\x00/", $value, $limit); + return preg_split('/\x00/', $value, $limit); } /**