-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(forge): fix stack overflow when the lib path is absolute. #9190
Conversation
Hi @l1nxy thanks for your PR! Would you mind adding a test case for this? We have some tests for remappings here as a reference: foundry/crates/forge/tests/cli/config.rs Lines 494 to 594 in ab8ebf6
|
@mattsse ping |
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.
makes sense, imo absolute paths should be discouraged
…y-rs#9190) * fix(forge): fix stack overflow when the lib path is absolute. * format * add test for setting absolute lib path. * remove useless code:
Motivation
Close #9127
The crash is caused by the recursive call of
get_mapping
in the config crate:foundry/crates/config/src/providers/remappings.rs
Lines 101 to 161 in c6d59b3
The
get_mapping
function calls thelib_foundry_toml_remappings
function:foundry/crates/config/src/providers/remappings.rs
Lines 196 to 211 in c6d59b3
In the
lib_foundry_toml_remappings
, it reads config from a nested lib folder. However, when the lib path inself.lib_paths
is absolute, it usesself.root.join(lib_path)
, it will produce wrong path if lib_path is absolute.The join function is described as follows:
Therefore, if the lib paths are absolute, they will only return the setting path and recursively search for nested libs.
Solution
I propose adding a check to determine whether the
lib
path is absolute or not. If it is absolute, we should return the root folder joined bylib
. Otherwise, we should return just the new path based on lib's relative path.By the way, I am not sure if setting an absolute path for the
lib
option in config is allowed. If we need to disable it, we can do so and print a warning message to inform users.