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

String operations should be documented and recognized as fallible #2623

Open
gibson042 opened this issue Jan 13, 2022 · 2 comments
Open

String operations should be documented and recognized as fallible #2623

gibson042 opened this issue Jan 13, 2022 · 2 comments
Labels

Comments

@gibson042
Copy link
Contributor

gibson042 commented Jan 13, 2022

cf. https://github.com/tc39/ecma402/pull/625/files#r784355422

ECMAScript String values are bounded to a maximum of 253 - 1 code units, but AFAICT no such limitation applies to specification types such as Lists or lexical input elements. As a result, it is possible to create internal values that cannot be represented as strings, but the specification defines no error when encountering situations that require doing just that. Some examples:

  • "x".repeat(2**53)
  • "ü".repeat(2**53 - 1).normalize("NFD")
  • "x".repeat(2**53 - 1).replace("x", "~~")
  • "ß".repeat(2**53 - 1).toLocaleUpperCase("en")
  • Function("//" + "x".repeat(2**53 - 3)).toString()
  • RegExp("x".repeat(2**53 - 1)).toString()
  • "x".repeat(2**53 - 1) + "!"
  • { printf 'let '; head -c 9007199254740992 /dev/zero | tr '\0' 'x'; } | eshost /dev/stdin (evaluation of LexicalBinding : BindingIdentifier invokes StringValue of BindingIdentifier, which calls CodePointsToString on its code points)
  • { head -c 9007199254740992 /dev/zero | tr '\0' 'x'; printf ': 0'; } | eshost /dev/stdin (evaluation of LabelledStatement : LabelIdentifier : LabelledItem invokes StringValue of LabelIdentifier, which calls CodePointsToString on its code points)

It seems like either string-concatenation, CodePointsToString, and other operations that concatenate strings should explicitly check bounds and throw a RangeError when they are exceeded, or some general text in The String Type should document that it always applies.

The good news is a lack of urgency here, because AFAICT every current implementation is incapable of dealing with anything near the limit.

@ljharb
Copy link
Member

ljharb commented Jan 13, 2022

Perhaps relevant, #641

@michaelficarra michaelficarra added editor call to be discussed in the next editor call spec bug and removed editor call to be discussed in the next editor call labels Jan 19, 2022
@bakkot
Copy link
Contributor

bakkot commented Jan 19, 2022

Yup, that's definitely wrong. Editors share your lack of urgency about this. That said, documenting the fact that these and other operations can throw because of real-world resources limitations probably merits attention before dealing with the spec-imposed limitations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants