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

Constructor for Symbol class in VM does not validate - should this be declared correct? #11669

Open
DartBot opened this issue Jul 2, 2013 · 7 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@DartBot
Copy link

DartBot commented Jul 2, 2013

This issue was originally filed by @mhausner


The VM version of the const constructor Symbol() is wrong. It has a non-const initializer.

const Symbol(String name)
      : this._name = validate(name);

I am implementing stricter constness checks in the VM right now and am removing the call to validate(). This results in corelib/symbol_test failing.

@floitschG
Copy link
Contributor

cc @peter-ahe-google.

@iposva-google
Copy link
Contributor

cc @gbracha.

@gbracha
Copy link
Contributor

gbracha commented Jul 3, 2013

I think that it would be quite reasonable for Symbol to encode any string. Symbol literals are syntactically restricted to (optionally qualified) identifiers but the class Symbol need not enforce that I think.

@peter-ahe-google
Copy link
Contributor

The current specification of Symbol was agreed upon in the initial specification and is implemented as a special rule in dart2js. The VM should be able to do the same.


Removed Area-Library label.
Added Area-VM label.

@floitschG
Copy link
Contributor

Issue #19636 has been merged into this issue.

@DartBot DartBot added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. labels Jun 30, 2014
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@zanderso zanderso added the closed-obsolete Closed as the reported issue is no longer relevant label Jan 5, 2017
@zanderso zanderso closed this as completed Jan 5, 2017
@ErikCorryGoogle ErikCorryGoogle changed the title const constructor for Symbol class has non-const initializer Constructor for Symbol class in VM does not validate - should this be declared correct? Jan 18, 2018
@lrhn
Copy link
Member

lrhn commented Jan 18, 2018

The current design requires special compiler recognition and handling of the Symbol constructor.

A const invocation of const Symbol(constantString) will need to check, at compile-time, that constantString is one of the allowed arguments, and then create a symbol value corresponding to it.
A non-const invocation, new Symbol(someString) will need to call a constructor that does validation of the argument, something that a const constructor cannot do.

It's current declaration signature is external const factory Symbol(String). That is a valid Dart declaration, so the libraries are valid (even if only technically so). The is no way the Symbol constructor can be implemented in plain Dart, it has to use compiler magic.

The VM's current approach is to just not implement the specified behavior. Apparently it hasn't been a problem (it does allow all the cases that should be allowed, it just allows more as well).

There are usability consequences, though. They cannot make it an error if someone tries to create a private symbol as const Symbol("_foo"), even though it will not create a private symbol and it is not equal to #_foo for any library (it is actually equal to the library name of a library with declaration library _foo;, so there is that). And, obviously, code written using the more lenient implementation won't work on other platforms.

@lrhn lrhn removed the closed-obsolete Closed as the reported issue is no longer relevant label Feb 15, 2019
@lrhn lrhn reopened this Feb 15, 2019
@lrhn
Copy link
Member

lrhn commented Feb 15, 2019

This is still an issue: The VM accepts arguments to the constructor which it is specified to reject.

On top of that, the VM assumes that a user provided symbol string does follow the specification, and mangles the user input.

var uri = Uri.parse("http://foo:bar@baz.qux/test.dyt");
var symbol = Symbol(uri.authority);  // Should be rejected.
print(symbol); // Prints Symbol("bar.qux").
print(#bar.qux); // Prints Symbol("bar.qux").
print(symbol == #bar.qux);  // false

This happens because the VM accepts unvalidated user inputs, but it also assumes that it can embed its own secret information in the string. Those two are choices are incompatible. The VM needs to either validate user inputs, or find a way to avoid that its internal representation clashes with user inputs (maybe insert escapes if the user input contains : or @, and remove those escapes in the unmangle method).

This is not a front-end issue, the issue happens with run-time created objects (the front end does check constants in the constant transformer, but apparently the VM doesn't use that).

(I'm personally OK with removing the need to validate symbol inputs, but then the VM still needs to avoid collisions with its internal string encodings).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

8 participants