From b78ce5ffd3f5751dc6f8a10b69385973798e6020 Mon Sep 17 00:00:00 2001 From: konstantin-s Date: Thu, 28 Jan 2021 17:21:46 +0500 Subject: [PATCH 1/3] Added support mbstring.func_overload=2 Probably resolves issue https://github.com/dompdf/dompdf/issues/2298 --- src/FontLib/Glyph/Outline.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FontLib/Glyph/Outline.php b/src/FontLib/Glyph/Outline.php index 330db09..f2b15d3 100644 --- a/src/FontLib/Glyph/Outline.php +++ b/src/FontLib/Glyph/Outline.php @@ -96,7 +96,7 @@ function parseData() { function encode() { $font = $this->getFont(); - return $font->write($this->raw, strlen($this->raw)); + return $font->write($this->raw, mb_strlen($this->raw, '8bit')); } function getSVGContours() { From 4281c76eed812732696836a765a4f7516111cbf2 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Sat, 11 Dec 2021 17:15:43 -0500 Subject: [PATCH 2/3] Use MBString functions for 8bit data read Prevents issues with MBString overrides of standard PHP functions. --- src/FontLib/EOT/File.php | 3 +-- src/FontLib/Table/DirectoryEntry.php | 4 ++-- src/FontLib/TrueType/File.php | 2 +- src/FontLib/WOFF/File.php | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/FontLib/EOT/File.php b/src/FontLib/EOT/File.php index 13d5925..cd3fff6 100644 --- a/src/FontLib/EOT/File.php +++ b/src/FontLib/EOT/File.php @@ -74,8 +74,7 @@ public function read($n) { } $string = fread($this->f, $n); - $chunks = str_split($string, 2); - $chunks = array_map("strrev", $chunks); + $chunks = mb_str_split($string, 2, '8bit'); return implode("", $chunks); } diff --git a/src/FontLib/Table/DirectoryEntry.php b/src/FontLib/Table/DirectoryEntry.php index 2b5846d..6a1c52a 100644 --- a/src/FontLib/Table/DirectoryEntry.php +++ b/src/FontLib/Table/DirectoryEntry.php @@ -37,14 +37,14 @@ class DirectoryEntry extends BinaryStream { protected $origF; static function computeChecksum($data) { - $len = strlen($data); + $len = mb_strlen($data, '8bit'); $mod = $len % 4; if ($mod) { $data = str_pad($data, $len + (4 - $mod), "\0"); } - $len = strlen($data); + $len = mb_strlen($data, '8bit'); $hi = 0x0000; $lo = 0x0000; diff --git a/src/FontLib/TrueType/File.php b/src/FontLib/TrueType/File.php index b61da0f..3594479 100644 --- a/src/FontLib/TrueType/File.php +++ b/src/FontLib/TrueType/File.php @@ -124,7 +124,7 @@ function parse() { } function utf8toUnicode($str) { - $len = strlen($str); + $len = mb_strlen($str, '8bit'); $out = array(); for ($i = 0; $i < $len; $i++) { diff --git a/src/FontLib/WOFF/File.php b/src/FontLib/WOFF/File.php index 9e54b3f..9056e94 100644 --- a/src/FontLib/WOFF/File.php +++ b/src/FontLib/WOFF/File.php @@ -50,7 +50,7 @@ public function load($file) { } // Prepare data ... - $length = strlen($data); + $length = mb_strlen($data, '8bit'); $entry->length = $entry->origLength = $length; $entry->offset = $dataOffset; From 5cce9d9a60e6a5d12d2e634b2fe54c07582e0621 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Sat, 11 Dec 2021 17:22:10 -0500 Subject: [PATCH 3/3] Require MBString PHP extension --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 6176f19..29b0653 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,9 @@ "config": { "bin-dir": "bin" }, + "require": { + "ext-mbstring": "*" + }, "require-dev": { "symfony/phpunit-bridge" : "^3 || ^4 || ^5" }