rbri · GitHub

This PR does the following

Fix Storage.setItem to correctly calculate store size when overwriting an existing key.

Problem

When setItem is called with a key that already exists, the store size calculation only adds the new value's length without subtracting the old value's length. This causes storeSize_ to grow monotonically even when the actual stored data size stays the same or shrinks, eventually triggering a spurious QuotaExceededError.

Reproducing

storage.setItem("key", "aaa"); // storeSize_ = 3
storage.setItem("key", "bb");  // storeSize_ = 5 (should be 2)
storage.setItem("key", "c");   // storeSize_ = 6 (should be 1)

After enough overwrites, storeSize_ exceeds STORE_SIZE_KIMIT even though the store only holds a single small value.

Read the original on github.com ↗