Skip to content

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

Closed

Description

@emilio

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

Activity

  1. added
    topic: forms
    on Sep 29, 2022
  2. domenic commented on Sep 29, 2022

    @domenic
    Member

    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....

  3. emilio commented on Sep 30, 2022

    @emilio
    ContributorAuthor

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

  4. emilio commented on Oct 2, 2022

    @emilio
    ContributorAuthor

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

  5. mfreed7 commented on Oct 3, 2022

    @mfreed7
    Contributor

    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?

  6. emilio commented on Oct 7, 2022

    @emilio
    ContributorAuthor

    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?

  7. emilio commented on Oct 7, 2022

    @emilio
    ContributorAuthor
  8. mfreed7 commented on Oct 11, 2022

    @mfreed7
    Contributor

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: forms

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions