summaryrefslogtreecommitdiffstats
path: root/src/UtfString.php
diff options
context:
space:
mode:
authorMichal Čihař <michal@cihar.com>2017-06-15 15:20:10 +0200
committerMichal Čihař <michal@cihar.com>2017-06-15 15:21:30 +0200
commite89c52b8d6734739a7fdc2c0ee06645ef9c5b697 (patch)
tree4886198d2673c4190943ee9ac8f730edcde2da10 /src/UtfString.php
parent7cad6fa657e8dd70704b4163bb09751d98408f9b (diff)
downloadsql-parser-e89c52b8d6734739a7fdc2c0ee06645ef9c5b697.zip
sql-parser-e89c52b8d6734739a7fdc2c0ee06645ef9c5b697.tar.gz
sql-parser-e89c52b8d6734739a7fdc2c0ee06645ef9c5b697.tar.bz2
Improve UtfString handling of invalid strings
First check whether string is actually utf-8 before trying to process it as it. Fixes https://github.com/phpmyadmin/phpmyadmin/issues/13385 Signed-off-by: Michal Čihař <michal@cihar.com>
Diffstat (limited to 'src/UtfString.php')
-rw-r--r--src/UtfString.php6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/UtfString.php b/src/UtfString.php
index e3dc512..0d2e0c5 100644
--- a/src/UtfString.php
+++ b/src/UtfString.php
@@ -75,7 +75,11 @@ class UtfString implements \ArrayAccess
$this->byteIdx = 0;
$this->charIdx = 0;
$this->byteLen = mb_strlen($str, '8bit');
- $this->charLen = mb_strlen($str, 'UTF-8');
+ if (! mb_check_encoding($str, 'UTF-8')) {
+ $this->charLen = 0;
+ } else {
+ $this->charLen = mb_strlen($str, 'UTF-8');
+ }
}
/**