microsoft / msphpsql

Microsoft Drivers for PHP for SQL Server
MIT License
1.8k stars 371 forks source link

Inserted text occassionally trailed by random characters after insert for strings of length 385 or greater #163

Closed ethan-tr closed 7 years ago

ethan-tr commented 8 years ago

After updating to 4.0.4 (from 4.0.2) I started experiencing an issue where data serialized with the json_encode or serialize function is randomly trailed by what look like random Chinese characters. The fields are nvarchar(max). I didn't change the character set in PHP or collation in the DB. Unfortunately this issue seems to happen randomly. I cannot reproduce it.

This is happening with PHP 7 on Ubuntu 16.04. The SQL Server version is 12.0.2000.8.

Update: This seems to only be an issue when the data is over roughly 1000 characters.

ianguerit commented 7 years ago

I'm seeing same issue, potentially related to #169 with string length and UTF-8 but for a text field type

meet-bhagdev commented 7 years ago

@ethan-tr We are working actively on a fix for this. Can you send us a repro that we can use to validate?

ethan-tr commented 7 years ago

@meet-bhagdev You can reproduce the issue with the script from #169, but shorten the message to:

$message = "Gluten-free Diet
Continuing from the last chapter about gluten sensitivity, people who suffers from disease who continues to consume food with gluten, it will most likely to cause mild to severe gastrointestinal discomfort, extreme cases could also affect nutrient absorption.
Considering the tradition of the Chinese food culture, most foods would contain gluten especially in Hong Kong and other Asian countries, eliminating foods such as rice, bread, and pasta etc. is almost inevitable, and it could also affect the quality of lifestyle, and most likely would become very dull and restricted. Therefore in order make people who are suffering from gluten sensitivity to adapt easily, I will now introduce a method of gluten-free eating.
Fresh vegetables and fruits (but excluding deep-fried foods such as tempura, or baked floury desserts such as apple pie or pineapple tarts)
Protein source: milk, cheese, yoghurts and fresh meat (but excluding meat that were under deep fried process such as chicken nuggets, deep fried cods) 
Drinks: 100% fruit juice, tea, coffee, cocoa";
ethan-tr commented 7 years ago

This string is the minimum length (385) that triggers the issue. If the string is any smaller the extra characters are not inserted.

$message = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
jan-kratochvil commented 7 years ago

Hi I have similar issue, but on selects. Could this be related? I checked the length and it seems strings size 385 and greater are affected with this problem. The server returns extra characters at the end on select. The fieldtype is text. Do you need any more info?

meet-bhagdev commented 7 years ago

@jan-kratochvil @ethan-tr @ianguerit This should be fixed with our latest release. You can upgrade using PECL: https://github.com/Microsoft/msphpsql/tree/PHP-7.0-Linux#install

If you need the binaries, we will be releasing them soon on GitHub