<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>137637</bug_id>
          
          <creation_ts>2014-10-11 11:06:30 -0700</creation_ts>
          <short_desc>Null character causes early string termination in Web SQL</short_desc>
          <delta_ts>2024-03-05 12:42:22 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Nolan Lawson">nolan</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>aaron.oneal</cc>
    
    <cc>ap</cc>
    
    <cc>beidson</cc>
    
    <cc>bfulgham</cc>
    
    <cc>dbates</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1041147</commentid>
    <comment_count>0</comment_count>
    <who name="Nolan Lawson">nolan</who>
    <bug_when>2014-10-11 11:06:30 -0700</bug_when>
    <thetext>Steps to reproduce the problem:
1. Store a string or blob in Web SQL containing the &quot;\u0000&quot; character
2. Retrieve it normally
3. Notice that everything is cut off after the \u0000

What is the expected behavior?
I expect the full string/blob to be returned

What went wrong?
The data was truncated. Here&apos;s a live example: http://bl.ocks.org/nolanlawson/9b5c13afb1ac0f7e70fe

This is especially bad when storing binary blobs, because if that binary data contains the 00 byte anywhere, then it will be cut off!

I&apos;ve also filed an issue on Chromium, since this bug seems to have been around for awhile: https://code.google.com/p/chromium/issues/detail?id=422690

A workaround is to use &quot;select hex()&quot; when getting back data that may contain a null character, but this is sub-optimal for performance, especially with binary blobs.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1041148</commentid>
    <comment_count>1</comment_count>
      <attachid>239681</attachid>
    <who name="Nolan Lawson">nolan</who>
    <bug_when>2014-10-11 11:07:07 -0700</bug_when>
    <thetext>Created attachment 239681
Test case in pure HTML</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1058197</commentid>
    <comment_count>2</comment_count>
    <who name="Aaron Oneal">aaron.oneal</who>
    <bug_when>2014-12-30 11:29:21 -0800</bug_when>
    <thetext>This same issue is in the Cordova Web SQL plugin.

The problem has to do with how SQLITE_TEXT columns in statement results are converted to strings.

This will repro the bug:

columnValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, i)];

Whereas this returns the correct full-length string:

columnValue = [[NSString alloc] initWithBytes:(char *)sqlite3_column_text(statement, i)
                                       length:sqlite3_column_bytes(statement, i)
                                     encoding:NSUTF8StringEncoding];

The former uses &apos;\0&apos; to determine string termination whereas the latter uses the specified buffer length.

I&apos;ll submit a fix for the Cordova plugin.

The WebKit issue is in WebCore/SQLiteStatement.cpp:

http://www.opensource.apple.com/source/WebCore/WebCore-332/platform/sql/SQLiteStatement.cpp

The getColumnValue() and getColumnText() functions rely on the standard String constructor:

return String(reinterpret_cast&lt;const UChar*&gt;(sqlite3_column_text16(m_statement, col)));

There is a String constructor that accepts a length, so a similar fix can probably be applied.

http://www.opensource.apple.com/source/WebCore/WebCore-332/platform/text/PlatformString.h</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1088589</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2015-04-25 14:57:35 -0700</bug_when>
    <thetext>&lt;rdar://problem/20699770&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2018855</commentid>
    <comment_count>4</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2024-03-05 12:42:22 -0800</bug_when>
    <thetext>Note: WebSQL has been disabled in our modern WebKit for some time, and is only still available as a backwards-compatibility affordance for very old legacy WebKit clients.

I&apos;m going to close this as WONT FIX since this feature is long-deprecated, and is no longer available in modern Web Browsing contexts.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>239681</attachid>
            <date>2014-10-11 11:07:07 -0700</date>
            <delta_ts>2014-10-11 11:07:07 -0700</delta_ts>
            <desc>Test case in pure HTML</desc>
            <filename>test-null-char.html</filename>
            <type>text/html</type>
            <size>2555</size>
            <attacher name="Nolan Lawson">nolan</attacher>
            
              <data encoding="base64">PGh0bWw+Cjxib2R5PgogIDxoMT5UZXN0IFx1MDAwMCBzdHJpbmcgdHJ1bmNhdGlvbiBpbiBXZWIg
U1FMPC9oMT4KICA8cD5EZXRhaWxzIDxhIGhyZWY9J2h0dHBzOi8vZ2l0aHViLmNvbS9wb3VjaGRi
L3BvdWNoZGIvcHVsbC8xNzMxI2lzc3VlY29tbWVudC0zODYyMjM0Mic+aW4gdGhpcyBQb3VjaERC
IGJ1ZzwvYT4uPC9wPgogIDxwcmUgaWQ9ImRpc3BsYXkiPjwvcHJlPgogIDxzY3JpcHQ+CiAgICAo
ZnVuY3Rpb24oKSB7CiAgICAgICd1c2Ugc3RyaWN0JzsKCiAgICAgIHZhciBkaXNwbGF5ID0gZG9j
dW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ2Rpc3BsYXknKTsKCiAgICAgIGZ1bmN0aW9uIGxvZyhzdHIp
IHsKICAgICAgICBkaXNwbGF5LmlubmVySFRNTCArPSAnXG4nICsgc3RyOwogICAgICB9CgogICAg
ICBmdW5jdGlvbiBkZWNvZ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ndGggb2YKICAgICAgICAgICAgLy8gdGhlIGhleCByZXR1cm5lZC4gcHJl
LTcuMSBTYWZhcmkgaXMgVVRGLTE2LgogICAgICAgICAgICB2YXIgZW5jb2RpbmcgPSBoZXgubGVu
Z3RoID09PSAxNCA/ICdVVEYtOCcgOiAnVVRGLTE2JzsKICAgICAgICAgICAgdmFyIHBhcnNlZCA9
IHBhcnNlSGV4U3RyaW5nKGhleCwgZW5jb2RpbmcpOwogICAgICAgICAgICBsb2coJ3BhcnNlZCBz
dHJpbmcgaXM6ICcgKyBKU09OLnN0cmluZ2lmeShwYXJzZWQpKTsKICAgICAgICAgICAgbG9nKCJ0
aGF0J3MgZnVubnksIHRoZSB3aG9sZSBzdHJpbmcgaXMgdGhlcmUgbm93ISIpOwoKICAgICAgICAg
IH0pOwogICAgICAgIH0pOwogICAgICB9LCBmdW5jdGlvbihlcnIpIHsKICAgICAgICBsb2coJ3Vu
ZXhwZWN0ZWQgZXJyb3I6ICcgKyBlcnIubWVzc2FnZSk7CiAgICAgIH0sIGZ1bmN0aW9uICgpIHsK
ICAgICAgfSk7CiAgICB9KSgpOwogIDwvc2NyaXB0Pgo8L2JvZHk+CjwvaHRtbD4=
</data>

          </attachment>
      

    </bug>

</bugzilla>