Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTMLOptionsCollection length setter should specify what happens when you go over the option limit. #8337

Closed
emilio opened this issue Sep 29, 2022 · 8 comments

Comments

@emilio
Copy link
Contributor

emilio commented Sep 29, 2022

https://html.spec.whatwg.org/#dom-htmloptionscollection-length has no limit on the number of options. That means that select.options.length = -1 would create INT32_MAX options, which is not great.

All browsers have an implementation limit to avoid blowing up with a snippet like the one below. WebKit and Gecko agree on that limit being 10000, but Blink seems to have changed that limit for some reason?

Test-case is:

document.createElement("select").options.length = -1

The behavior where the limit is surpassed is undefined: Gecko throws, WebKit/Blink just warn to the console. We can probably standardize on the WebKit / Blink behavior (just do nothing), but the spec should probably explicitly mention this.

I'm also curious about why the limit was changed in Blink?

cc @mfreed7

@emilio
Copy link
Contributor Author

emilio commented Sep 29, 2022

@domenic
Copy link
Member

domenic commented Sep 29, 2022

I found when Blink changed: https://source.chromium.org/chromium/chromium/src/+/a736194f01cfbb2688134cdfdf66f85996719ee4

We had 10,000 limit only when we add OPTIONs via IDL features, and no limit for OPTIONs added by the HTML parser. We observed 40,000+ OPTIONs were practically used, and the 10,000 limit didn't make sense.

I guess the point is it'd be weird if you had <select>... 50_000 options ...</select> via the parser, and then did select.options.length++, that would truncate you down to 10_000 options. Hmm....

@emilio
Copy link
Contributor Author

emilio commented Sep 30, 2022

In Gecko and WebKit it wouldn't truncate, it just won't do anything.

emilio added a commit to emilio/html that referenced this issue Oct 2, 2022
This aligns with WebKit's behavior as per the discussion in
whatwg#8337.
@emilio
Copy link
Contributor Author

emilio commented Oct 2, 2022

#8347 is the PR for this. Tests are up in the mozilla bug (a volunteer contributed the patch).

@mfreed7
Copy link
Contributor

mfreed7 commented Oct 3, 2022

I'm ok with the spec and behavior having a reasonable limit, much smaller than INT_MAX. However, I don't think we should start throwing when that limit is exceeded, since that could break things. I think a console warning and a refusal to set lengths > SPEC_LIMIT should hopefully be enough to keep people from having problems, right?

In Gecko and WebKit it wouldn't truncate, it just won't do anything.

In Chromium also, I think: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/html/forms/html_select_element.cc;l=485;drc=a2a75509d6058498d6e00ca225455a53b1006188

Given the comment that options lists of 40k+ were observed (5 years ago), perhaps we should choose a limit like 100,000?

emilio added a commit to emilio/html that referenced this issue Oct 6, 2022
This aligns with WebKit's behavior as per the discussion in
whatwg#8337.
@emilio
Copy link
Contributor Author

emilio commented Oct 7, 2022

I don't feel too strongly about the precise limit. 10000 matches two of the three engines and I've never seen a bug about people requesting more, so I don't think we need to raise it, but I wouldn't be opposed to do so... How strongly do you feel about it @mfreed7?

@emilio
Copy link
Contributor Author

emilio commented Oct 7, 2022

Ok as per #8347 (comment), raising it to 100000 sounds good to me. @rniwa @smfr @nt1m, would WebKit be fine with raising it?

It'd be just adding one zero here: https://searchfox.org/wubkat/rev/e8e9be7353991aee7df45aa62f0e0148f16e6f9f/Source/WebCore/html/HTMLSelectElement.cpp#69

@mfreed7
Copy link
Contributor

mfreed7 commented Oct 11, 2022

I don't feel too strongly about the precise limit. 10000 matches two of the three engines and I've never seen a bug about people requesting more, so I don't think we need to raise it, but I wouldn't be opposed to do so... How strongly do you feel about it @mfreed7?

I’m just worried about compat, given that it’s lower than before and the comment in our codebase suggesting problems with 40,000.

emilio added a commit to emilio/html that referenced this issue Oct 17, 2022
This aligns with WebKit's behavior, but bumps the limit with 100k, as
per the discussion in whatwg#8337.

Co-authored-by: Domenic Denicola <[email protected]>
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 10, 2022
Update the const kMaxListItems to be 100,000 in HTMLOptionsCollections
to reflect updated spec. Also, this max should only be used when new
length is greater than current length.

[1] https://html.spec.whatwg.org/#dom-htmloptionscollection-length
[2] whatwg/html#8337
[3] whatwg/html#8347

Change-Id: I7ff54e9cfdcb2eb014ad508485eda6908308314b
Fixed: 1370370
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 11, 2022
Update the const kMaxListItems to be 100,000 in HTMLOptionsCollections
to reflect updated spec. Also, this max should only be used when new
length is greater than current length.

[1] https://html.spec.whatwg.org/#dom-htmloptionscollection-length
[2] whatwg/html#8337
[3] whatwg/html#8347

Change-Id: I7ff54e9cfdcb2eb014ad508485eda6908308314b
Fixed: 1370370
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4015681
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Di Zhang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1070388}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 11, 2022
Update the const kMaxListItems to be 100,000 in HTMLOptionsCollections
to reflect updated spec. Also, this max should only be used when new
length is greater than current length.

[1] https://html.spec.whatwg.org/#dom-htmloptionscollection-length
[2] whatwg/html#8337
[3] whatwg/html#8347

Change-Id: I7ff54e9cfdcb2eb014ad508485eda6908308314b
Fixed: 1370370
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4015681
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Di Zhang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1070388}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Nov 21, 2022
…ection.length setter, a=testonly

Automatic update from web-platform-tests
Restore 100,000 limit in HTMLOptionsCollection.length setter

Update the const kMaxListItems to be 100,000 in HTMLOptionsCollections
to reflect updated spec. Also, this max should only be used when new
length is greater than current length.

[1] https://html.spec.whatwg.org/#dom-htmloptionscollection-length
[2] whatwg/html#8337
[3] whatwg/html#8347

Change-Id: I7ff54e9cfdcb2eb014ad508485eda6908308314b
Fixed: 1370370
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4015681
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Di Zhang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1070388}

--

wpt-commits: 893a5f3fa49a459b94526de606e89856dcbb5dae
wpt-pr: 36917
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Nov 21, 2022
…ection.length setter, a=testonly

Automatic update from web-platform-tests
Restore 100,000 limit in HTMLOptionsCollection.length setter

Update the const kMaxListItems to be 100,000 in HTMLOptionsCollections
to reflect updated spec. Also, this max should only be used when new
length is greater than current length.

[1] https://html.spec.whatwg.org/#dom-htmloptionscollection-length
[2] whatwg/html#8337
[3] whatwg/html#8347

Change-Id: I7ff54e9cfdcb2eb014ad508485eda6908308314b
Fixed: 1370370
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4015681
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Di Zhang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1070388}

--

wpt-commits: 893a5f3fa49a459b94526de606e89856dcbb5dae
wpt-pr: 36917
webkit-early-warning-system pushed a commit to Ahmad-S792/WebKit that referenced this issue Feb 27, 2023
https://bugs.webkit.org/show_bug.cgi?id=252983

Reviewed by Chris Dumez.

This patch is to align WebKit with Blink / Chromium and Gecko / Firefox.

Merge - https://chromium.googlesource.com/chromium/src/+/f27e6ea87ecf211c8b8644813422a9e7f19cd1cc

This patch updates 'maxSelectItems' to new value of 100,000
to reflect update in spec.
Further, it is updated to be only used when new length is
greater than current length.
Additionally, add comments to reflect the details as needed.

Web-Spec: https://html.spec.whatwg.org/#dom-htmloptionscollection-length
Issue: whatwg/html#8337

* Source/WebCore/html/HTMLSelectElement.cpp:
(maxSelectItems): Update constant value
(HTMLSelectElement::setItem): Remove '=' and update comments and console message
(HTMLSelectElement::setLength): Add comment and update console message
* LayoutTests/imported/w3c/web-platform-tests/html/select/options-length-too-large.html: Add Test Case
* LayoutTests/imported/w3c/web-platform-tests/html/select/options-length-too-large-expected.txt: Add Test Case Expectation
* LayoutTests/fast/forms/select-max-length-expected.txt: Rebaselined
* LayoutTests/fast/dom/HTMLSelectElement/select-selectedIndex-multiple-expected.txt: Rebaselined
* LayoutTests/fast/dom/HTMLSelectElement/select-selectedIndex-expected.txt: Rebaselined

Canonical link: https://commits.webkit.org/260896@main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants