From 6c462836a7964fb6cb39d1153112617b0c3abf59 Mon Sep 17 00:00:00 2001 From: =?utf8?q?M=C3=A1t=C3=A9=20Szab=C3=B3?= Date: Mon, 8 Jul 2019 18:05:22 +0200 Subject: [PATCH] Make MSCompoundFileReader::readFile platform-agnostic MSCompoundFileReader::readFile uses iconv to convert information given in UTF-16 character set with little-endian byte order to the UTF-8 character set. The input string has no BOM and the byte order is not explicitly given, causing iconv to try to guess the byte order based on the host operating system. This causes the method to return different results for the same file in different environments. This patch explicitly provides the byte order for the input to be converted (UTF-16LE) to ensure portability and predictability. As part of this, move MSCompoundFileReaderTest into the unit test tree. Bug: T225019 Change-Id: I62154897d303b28c288c3a4f2f5456bedcc81852 --- includes/libs/mime/MSCompoundFileReader.php | 2 +- .../{ => unit}/includes/libs/mime/MSCompoundFileReaderTest.php | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/phpunit/{ => unit}/includes/libs/mime/MSCompoundFileReaderTest.php (100%) diff --git a/includes/libs/mime/MSCompoundFileReader.php b/includes/libs/mime/MSCompoundFileReader.php index aea0a02f60..8afaa38e02 100644 --- a/includes/libs/mime/MSCompoundFileReader.php +++ b/includes/libs/mime/MSCompoundFileReader.php @@ -333,7 +333,7 @@ class MSCompoundFileReader { continue; } - $name = iconv( 'UTF-16', 'UTF-8', substr( $entry['name_raw'], 0, $entry['name_length'] - 2 ) ); + $name = iconv( 'UTF-16LE', 'UTF-8', substr( $entry['name_raw'], 0, $entry['name_length'] - 2 ) ); $clsid = $this->decodeClsid( $entry['clsid'] ); if ( $type == self::TYPE_ROOT && isset( self::$mimesByClsid[$clsid] ) ) { diff --git a/tests/phpunit/includes/libs/mime/MSCompoundFileReaderTest.php b/tests/phpunit/unit/includes/libs/mime/MSCompoundFileReaderTest.php similarity index 100% rename from tests/phpunit/includes/libs/mime/MSCompoundFileReaderTest.php rename to tests/phpunit/unit/includes/libs/mime/MSCompoundFileReaderTest.php -- 2.20.1