<?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>245479</bug_id>
          
          <creation_ts>2022-09-21 08:12:41 -0700</creation_ts>
          <short_desc>REGRESSION (iOS 16): LocalStorage is cleared after quota error</short_desc>
          <delta_ts>2023-02-21 05:33:17 -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>Website Storage</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>iOS 16</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Olexiy">alexey.buki</reporter>
          <assigned_to name="Sihui Liu">sihui_liu</assigned_to>
          <cc>akif.abasov</cc>
    
    <cc>nham</cc>
    
    <cc>sihui_liu</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1900139</commentid>
    <comment_count>0</comment_count>
      <attachid>462504</attachid>
    <who name="Olexiy">alexey.buki</who>
    <bug_when>2022-09-21 08:12:41 -0700</bug_when>
    <thetext>Created attachment 462504
test script that is shown the problem

IOS16 Safari: LocalStorage is cleared after writing data of more than ~2.5MB.

After upgrading on IOS 16 we were faced the problem clearing data in localStorage.When we try to write data that size is more than ~2.5MB or all amount of data more than ~2.5MB the LocalStorage is being cleared without any errors and warnings in Safari. I could not reproduce the problem in other browsers or platforms.

Step to reproduce:
- Go to IOS 16 Safari 
- Open any website
- try to write data more than ~2.5MB (the attached test script helps you to display the problem)
- check your localStorage

Actial result:
your localStorage is empty

Expected result:
your localStorage should be filled your data or it should be thrown an exception if quota is exceeded

Please consider the problem ASAP.

Thank you in advance!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1900283</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-09-21 19:25:43 -0700</bug_when>
    <thetext>&lt;rdar://problem/100252023&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1901565</commentid>
    <comment_count>2</comment_count>
    <who name="Sihui Liu">sihui_liu</who>
    <bug_when>2022-09-27 10:43:55 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/4758</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1902444</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2022-09-30 13:37:11 -0700</bug_when>
    <thetext>Committed 255044@main (0297f1253a4f): &lt;https://commits.webkit.org/255044@main&gt;

Reviewed commits have been landed. Closing PR #4758 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1902757</commentid>
    <comment_count>4</comment_count>
    <who name="Olexiy">alexey.buki</who>
    <bug_when>2022-10-03 00:45:03 -0700</bug_when>
    <thetext>Can you share the IOS version where the issue will be fixed?

thank you in advance!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1911938</commentid>
    <comment_count>5</comment_count>
    <who name="Ben Nham">nham</who>
    <bug_when>2022-11-11 17:25:02 -0800</bug_when>
    <thetext>I don&apos;t think this test script is correct. It measures the string length of all values in LocalStorage. But LocalStorage is persisted, and it&apos;s the size of the persisted string that matters for quota computations.

Currently in WebKit, LocalStorage string values are persisted as UTF-16 (2 bytes per character)--see the call to SQLiteStatement::bindBlob(StringView) in SQLiteStorageArea::setItem. So I would expect that you could only store 2.5 million characters before exceeding your quota on disk.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1911961</commentid>
    <comment_count>6</comment_count>
    <who name="Ben Nham">nham</who>
    <bug_when>2022-11-11 21:15:57 -0800</bug_when>
    <thetext>Note that Chrome implements LocalStorage in the exact same manner: string values are persisted as UTF-16, so they use 2 bytes per character. However, their quota for LocalStorage is 10 MB (https://chromiumcodereview.appspot.com/21680002), so when you run your test case, you can store 5 million characters.

We could possibly address this by discussing whether it&apos;s a good idea to bump up our quota as well. However, given the current 5 MB quota, the fact that you can only store 2.5 million characters in your test case is intended and things are working as expected.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1912351</commentid>
    <comment_count>7</comment_count>
    <who name="Sihui Liu">sihui_liu</who>
    <bug_when>2022-11-14 09:46:44 -0800</bug_when>
    <thetext>Reopened as 255044@main is reverted in https://bugs.webkit.org/show_bug.cgi?id=247767.

As Ben mentioned, WebKit stores string in LocalStorage as UTF-16, so it is expected that 5MB quota only allows about 2.5 million characters. The was implemented way before iOS 16, so likely not a regression.

However, this could still be a compatibility issue as Safari has different behavior than Chrome and Firefox, so we should keep this bug and figure out how to solve it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1912583</commentid>
    <comment_count>8</comment_count>
    <who name="Olexiy">alexey.buki</who>
    <bug_when>2022-11-15 05:46:38 -0800</bug_when>
    <thetext>This issue is a regression because localStorage is cleared when the amount of storage is reached more than 2.5 million characters. It could not be reproduced before ios16.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1912658</commentid>
    <comment_count>9</comment_count>
    <who name="Sihui Liu">sihui_liu</who>
    <bug_when>2022-11-15 10:18:50 -0800</bug_when>
    <thetext>(In reply to Olexiy from comment #8)
&gt; This issue is a regression because localStorage is cleared when the amount
&gt; of storage is reached more than 2.5 million characters. It could not be
&gt; reproduced before ios16.

Oh so the regression is &quot;LocalStorage is cleared after quota error&quot;, not &quot;LocalStorage throws quota error after writing 2.5 million characters&quot;. Updated title to reflect that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1913241</commentid>
    <comment_count>10</comment_count>
    <who name="Sihui Liu">sihui_liu</who>
    <bug_when>2022-11-17 11:17:44 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/6597</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1913601</commentid>
    <comment_count>11</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2022-11-18 17:23:57 -0800</bug_when>
    <thetext>Committed 256863@main (5bc131992783): &lt;https://commits.webkit.org/256863@main&gt;

Reviewed commits have been landed. Closing PR #6597 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1935483</commentid>
    <comment_count>12</comment_count>
    <who name="Akif">akif.abasov</who>
    <bug_when>2023-02-21 05:33:17 -0800</bug_when>
    <thetext>It&apos;s even more broken in Safari Tech Preview https://bugs.webkit.org/show_bug.cgi?id=252661</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>462504</attachid>
            <date>2022-09-21 08:12:41 -0700</date>
            <delta_ts>2022-09-21 08:12:41 -0700</delta_ts>
            <desc>test script that is shown the problem</desc>
            <filename>defineMaxSizeLs.js</filename>
            <type>text/javascript</type>
            <size>832</size>
            <attacher name="Olexiy">alexey.buki</attacher>
            
              <data encoding="base64">ZnVuY3Rpb24gZGVmaW5lTWF4U2l6ZUxzICgpIHsKICAgIGNvbnN0IGl0ZW1TaXplID0gMTAyNCAq
IDEwOwogICAgbGV0IG1heFNpemUgPSAwOwogICAgbGV0IGkgPSAwOwogICAgbGV0IGJ1ZmZlciA9
ICcnOwoKICAgIGZvciAobGV0IGsgPSAwOyBrIDwgaXRlbVNpemU7IGsrKykgewogICAgICAgIGJ1
ZmZlciArPSAnMCc7CiAgICB9CgogICAgY29uc3QgZ2V0U3RvcmFnZVNpemUgPSAoKSA9PiB7CiAg
ICAgICAgdmFyIG9jY3VwaWVkID0gMDsKCiAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCBsb2Nh
bFN0b3JhZ2UubGVuZ3RoOyBqKyspIHsKICAgICAgICAgICAgb2NjdXBpZWQgKz0gbG9jYWxTdG9y
YWdlW2xvY2FsU3RvcmFnZS5rZXkoaildLmxlbmd0aDsKICAgICAgICB9CgogICAgICAgIHJldHVy
biBvY2N1cGllZDsKICAgIH07CgogICAgY29uc3QgcnVuID0gKCkgPT4gewogICAgICAgIGNvbnNv
bGUubG9nKCdleHBlY3RlZCBzaXplID0gJywgbWF4U2l6ZSwgJ2FjdHVhbCBzaXplID0gJywgZ2V0
U3RvcmFnZVNpemUoKSk7CgogICAgICAgIHRyeSB7CiAgICAgICAgICAgIGxvY2FsU3RvcmFnZS5z
ZXRJdGVtKCdfX190ZXN0JyArIGksIGJ1ZmZlcik7CgogICAgICAgICAgICBzZXRUaW1lb3V0KCgp
ID0+IHsKICAgICAgICAgICAgICAgIG1heFNpemUgKz0gaXRlbVNpemU7CiAgICAgICAgICAgICAg
ICArK2k7CiAgICAgICAgICAgICAgICBydW4oKTsKICAgICAgICAgICAgfSwgMTAwKTsKICAgICAg
ICB9IGNhdGNoKGUpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coJ21heCBzaXplJywgbWF4U2l6
ZSk7CiAgICAgICAgfQogICAgfTsKCiAgICBydW4oKTsKfQ==
</data>

          </attachment>
      

    </bug>

</bugzilla>