Bug #76726 [Opn->Asn]: Segmentation fault when fetching truncated 4 bytes Unicode character
| From: | cmb@php.net | Date: | Mon, 13 Aug 2018 11:01:16 +0000 |
| Subject: | Bug #76726 [Opn->Asn]: Segmentation fault when fetching truncated 4 bytes Unicode character | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216762@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76726&edit=1
ID: 76726
Updated by: cmb@php.net
Reported by: maxiwheat at gmail dot com
Summary: Segmentation fault when fetching truncated 4 bytes
Unicode character
-Status: Open
+Status: Assigned
Type: Bug
Package: PDO DBlib
Operating System: Linux Slackware 14.1
PHP Version: 7.2.8
-Assigned To:
+Assigned To: adambaratz
Block user comment: N
Private report: N
New Comment:
Adam, could you have a look at this issue, please?
Previous Comments:
------------------------------------------------------------------------
[2018-08-09 18:27:43] maxiwheat at gmail dot com
Arggggg cannot even post the bug correctly,,, it does not appear correctly here.... character that
produce the bug is the christmas tree : https://emojipedia.org/christmas-tree/
// ???? should be a christmas tree emoji
$sql = "DECLARE @test AS NVARCHAR(1) = N'????'; SELECT @test AS test;";
------------------------------------------------------------------------
[2018-08-09 18:23:04] maxiwheat at gmail dot com
SQL query got saved badly, should be :
$sql = "DECLARE @test AS NVARCHAR(1) = N'????'; SELECT @test AS test;";
------------------------------------------------------------------------
[2018-08-09 18:21:26] maxiwheat at gmail dot com
a
------------------------------------------------------------------------
[2018-08-09 18:17:07] maxiwheat at gmail dot com
Description:
------------
We experienced this issue when a string was inserted in a table column of type NVARCHAR and that
string ended with a 4 bytes unicode character, but the column was not large enough to contain the
whole string, so the string got truncated, but instead of truncating the whole 4 bytes character it
got truncated in the middle (because SQL Server stores string as USC-2, 2 bytes per character) and
becoming an invalid unicode character. With SQL Server Management Studio, we can still query that
column without issues, except that the character is replaced by an invalid character (�)
Test script:
---------------
$conn = new PDO('dblib:host=myhost.local;dbname=MyDB;charset=UTF-8;', 'myuser',
'mypass');
$sql = "DECLARE @test AS NVARCHAR(1) = N'????'; SELECT @test AS test;";
$stmt = $conn->prepare($sql);
$stmt->execute();
// Skip rowcount result
$stmt->nextRowset();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo $row['test'];
Expected result:
----------------
Outputs truncated string/byte like � or an empty string, does not segfault.
Actual result:
--------------
Segmentation fault
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76726&edit=1