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

fix(compiler-cli): handle pseudo cycles in inline source-maps #40435

Conversation

petebacondarwin
Copy link
Member

When a source-map has an inline source, any source-map linked from
that source should only be loaded if itself is also inline; it should not
attempt to load a source-map from the file-system. Otherwise we can
find ourselves with inadvertent infinite cyclic dependencies.

For example if a transpiler takes a file (e.g. index.js) and generates
a new file overwriting the original file (but capturing the original
source inline in the new source-map (index.js.map) the source
file loader might read the inline original file (also index.js) and
then try to load the index.js.map file from disk - ad infinitum.

Fixes #40408

@petebacondarwin petebacondarwin added target: patch This PR is targeted for the next patch release area: compiler Issues related to `ngc`, Angular's template compiler labels Jan 14, 2021
@ngbot ngbot bot modified the milestone: Backlog Jan 14, 2021
@google-cla google-cla bot added the cla: yes label Jan 14, 2021
@petebacondarwin petebacondarwin force-pushed the source-maps-self-referencin-inline-issue-40408 branch from d68569a to b6af801 Compare January 15, 2021 11:15
@petebacondarwin petebacondarwin force-pushed the source-maps-self-referencin-inline-issue-40408 branch 3 times, most recently from c0a2aeb to 02ad8f0 Compare January 15, 2021 19:16
@petebacondarwin petebacondarwin marked this pull request as ready for review January 15, 2021 19:41
@pullapprove pullapprove bot requested a review from JoostK January 15, 2021 19:42
@petebacondarwin petebacondarwin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jan 15, 2021
@petebacondarwin petebacondarwin marked this pull request as draft January 15, 2021 20:38
@petebacondarwin petebacondarwin removed the request for review from JoostK January 15, 2021 20:38
@petebacondarwin petebacondarwin force-pushed the source-maps-self-referencin-inline-issue-40408 branch 2 times, most recently from 9ddfdee to 806ad70 Compare January 16, 2021 17:03
@petebacondarwin petebacondarwin marked this pull request as ready for review January 16, 2021 17:09
@pullapprove pullapprove bot requested a review from JoostK January 16, 2021 17:09
@petebacondarwin petebacondarwin force-pushed the source-maps-self-referencin-inline-issue-40408 branch 3 times, most recently from b62779d to a79bfe1 Compare January 17, 2021 14:48
Comment on lines +152 to +154
// The source file was provided inline and its contents did not include an inline source-map.
// So we don't try to load an external source-map from the file-system, since this can lead to
// invalid circular dependencies.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there be legitimate cases that will now hit this case and fail to load? i.e. a source map that references another source file inline, which has an external source map comment to a source map file that actually exists? If I understand correctly, that scenario will be rejected now where the external source map file is refused to load.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this. And of course it is feasible that this might happen. But I believe that in practice it will not: our library builds will not do this. Further, I think that there is just as good a chance that trying to load something from the disk from something that was inline is just as likely to produce a failure of some kind.

The bottom line is that anything is possible, I don't think it is possible to handle everything and most of these corner cases will be wrong in some way or another anyway whatever we do!

When a source-map has an inline source, any source-map linked from
that source should only be loaded if itself is also inline; it should not
attempt to load a source-map from the file-system. Otherwise we can
find ourselves with inadvertent infinite cyclic dependencies.

For example, if a transpiler takes a file (e.g. index.js) and generates
a new file overwriting the original file - capturing the original
source inline in the new source-map (index.js.map) - the source
file loader might read the inline original file (also index.js) and
then try to load the `index.js.map` file from disk - ad infinitum.

Note that the first call to `loadSourceFile()` is special, since you can
pass in the source-file and source-map contents directly as in-memory
strrngs. This is common if the transpiler has just generated these and has
not yet written them to disk.
When the contents are passed into `loadSourceFile()` directly, they are
not treated as "inline" for the purposes described above since there is
no chance of these "in-memory" source and source-map contents being caught
up in a cyclic dependency.

Fixes angular#40408
@petebacondarwin petebacondarwin force-pushed the source-maps-self-referencin-inline-issue-40408 branch from fa4d239 to 965c0e7 Compare January 20, 2021 22:09
@petebacondarwin petebacondarwin added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 21, 2021
jessicajaniuk pushed a commit that referenced this pull request Jan 21, 2021
When a source-map has an inline source, any source-map linked from
that source should only be loaded if itself is also inline; it should not
attempt to load a source-map from the file-system. Otherwise we can
find ourselves with inadvertent infinite cyclic dependencies.

For example, if a transpiler takes a file (e.g. index.js) and generates
a new file overwriting the original file - capturing the original
source inline in the new source-map (index.js.map) - the source
file loader might read the inline original file (also index.js) and
then try to load the `index.js.map` file from disk - ad infinitum.

Note that the first call to `loadSourceFile()` is special, since you can
pass in the source-file and source-map contents directly as in-memory
strrngs. This is common if the transpiler has just generated these and has
not yet written them to disk.
When the contents are passed into `loadSourceFile()` directly, they are
not treated as "inline" for the purposes described above since there is
no chance of these "in-memory" source and source-map contents being caught
up in a cyclic dependency.

Fixes #40408

PR Close #40435
@petebacondarwin petebacondarwin deleted the source-maps-self-referencin-inline-issue-40408 branch January 27, 2021 09:36
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Circular source file mapping dependency on extract-i18n
2 participants