Bug #76726 [Opn]: Segmentation fault when fetching truncated 4 bytes Unicode character
Edit report at https://bugs.php.net/bug.php?id=76726&edit=1
ID: 76726
User updated by: maxiwheat at gmail dot com
Reported by: maxiwheat at gmail dot com
Summary: Segmentation fault when fetching truncated 4 bytes
Unicode character
Status: Open
Type: Bug
Package: PDO DBlib
Operating System: Linux Slackware 14.1
PHP Version: 7.2.8
Block user comment: N
Private report: N
New Comment:
SQL query got saved badly, should be :
$sql = "DECLARE @test AS NVARCHAR(1) = N'ð'; SELECT @test AS test;";
Previous Comments:
------------------------------------------------------------------------
[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
Thread (5 messages)