diff --git a/framework/Pack/lib/Horde/Pack.php b/framework/Pack/lib/Horde/Pack.php index d7dfcb04660..60f77c97300 100644 --- a/framework/Pack/lib/Horde/Pack.php +++ b/framework/Pack/lib/Horde/Pack.php @@ -126,7 +126,11 @@ public function pack($data, array $opts = array()) * 128 - RESERVED for future use (if set, indicates that initial * byte will extend into next byte). * Packed (and compressed data) follows this byte. */ - $packed = $val->pack($data); + try { + $packed = $val->pack($data); + } catch (Horde_Pack_Exception $e) { + continue; + } if ($opts['compress'] !== false) { if ($opts['compress'] === 0) { diff --git a/framework/Pack/lib/Horde/Pack/Driver/Json.php b/framework/Pack/lib/Horde/Pack/Driver/Json.php index dc78e26367a..6afb3c9043d 100644 --- a/framework/Pack/lib/Horde/Pack/Driver/Json.php +++ b/framework/Pack/lib/Horde/Pack/Driver/Json.php @@ -37,12 +37,17 @@ static public function supported() */ public function pack($data) { + $d = json_encode($data); + if (json_last_error() === 5) { + throw new Horde_Pack_Exception('Non UTF-8 data cannot be JSON packed.'); + } + /* For JSON, we need to keep track whether the initial data was * an object or class. The initial JSON character is one of the * following: * 0: Non-array * 1: Array */ - return intval(is_array($data)) . json_encode($data); + return intval(is_array($data)) . $d; } /** diff --git a/framework/Pack/package.xml b/framework/Pack/package.xml index dfa0a981ea3..1f2efc0e38b 100644 --- a/framework/Pack/package.xml +++ b/framework/Pack/package.xml @@ -21,7 +21,7 @@ LGPL-2.1 -* +* [mms] Don't use JSON driver to pack if input contains non-UTF8 data (Bug #13275). @@ -182,7 +182,7 @@ 2014-04-03 LGPL-2.1 -* +* [mms] Don't use JSON driver to pack if input contains non-UTF8 data (Bug #13275). diff --git a/framework/Pack/test/Horde/Pack/PackTest.php b/framework/Pack/test/Horde/Pack/PackTest.php index 65d6d167432..be0f2391bc5 100644 --- a/framework/Pack/test/Horde/Pack/PackTest.php +++ b/framework/Pack/test/Horde/Pack/PackTest.php @@ -34,4 +34,25 @@ public function testExpectedExceptionOnSerialize() serialize($pack); } + // Bug #13275 + public function testNonUtf8Pack() + { + // ISO-8859-1 string + $data = base64_decode('VORzdA=='); + + $pack = new Horde_Pack(); + + $p = $pack->pack($data, array( + 'drivers' => array( + 'Horde_Pack_Driver_Json', + 'Horde_Pack_Driver_Serialize' + ) + )); + + $this->assertEquals( + $data, + $pack->unpack($p) + ); + } + }