-
-
Notifications
You must be signed in to change notification settings - Fork 27
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: Prevent infinite loop #90
Conversation
Hi, can you post an example sourcemap for which this change makes a difference? Intuitively it shouldn't, now I'm wondering if there's something wrong with our logic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the change itself looks good to me, though I believe this only papers over a bug that exists elsewhere.
I remember there was a similar case where it would just iterate forever (or rather, until the int wraps around and catches up) when you add tokens out of order.
The problem there being that the serialization step assumes the API user adds tokens in order, and out of order tokens result in serialization being messed up.
The better solution there would actually be to ensure tokens are properly sorted. And to remove that API footgun that assumes the user does the right thing, one way would be to just sort the token list prior to serialization.
@Swatinem Yeah, I assumed it was something like this. Out-of-order tokens have never made sense and just shouldn't exist. |
I did Source map files are uploaded at https://gist.github.com/kdy1/000301fc6091b3e8d5aec7cef8e89b80 Exact code: let mut map = builder.into_sourcemap();
let mut map_s = vec![];
map.to_writer(&mut map_s).unwrap();
std::fs::write("transform.js.map", map_s).unwrap();
if let Some(orig) = orig {
let mut map_s = vec![];
orig.to_writer(&mut map_s).unwrap();
std::fs::write("orig.js.map", map_s).unwrap();
let mut copied = orig.clone();
copied.adjust_mappings(&map);
map = copied;
}
map.to_writer(&mut vec![]).unwrap(); // Fails with a panic caused by an overflow of integer
map |
Thank you! I agree that my fix is wrong. I tried reproducing it with a single source map but it seems like my fix simply removes erroneous tokens from the output |
Context: swc-project/swc#9050
kdy1/rust-sourcemap.git#skip-range
I used
adjust_mapping
, but I foundsourcemap
crate is panicking with integer overflow. The cause wasso I modified it to
and it worked.