Skip to content

Fix Storage's storeSize calculation when overwriting existing key#1095

Merged
rbri merged 1 commit intoHtmlUnit:masterfrom
duonglaiquang:duong_storage
Mar 12, 2026
Merged

Fix Storage's storeSize calculation when overwriting existing key#1095
rbri merged 1 commit intoHtmlUnit:masterfrom
duonglaiquang:duong_storage

Conversation

@duonglaiquang
Copy link
Contributor

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.

@sonarqubecloud
Copy link

@rbri rbri merged commit a81b0d1 into HtmlUnit:master Mar 12, 2026
8 checks passed
@rbri
Copy link
Member

rbri commented Mar 12, 2026

Thanks a lot, have added also a test for that, all works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants