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

Hang on symlink loop in library #1593

Closed
per1234 opened this issue Dec 16, 2021 · 0 comments · Fixed by #2146
Closed

Hang on symlink loop in library #1593

per1234 opened this issue Dec 16, 2021 · 0 comments · Fixed by #2146
Assignees
Labels
conclusion: resolved Issue was resolved criticality: medium Of moderate impact topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Dec 16, 2021

Bug Report

Current behavior

When loading a library or sketch that contains multiple symlinks to a parent path, Arduino CLI locks up in a perpetual loop.

Expected behavior

Either handle the loop or else fail with an error that clearly communicates the problem to the user.

Environment

  • CLI version: nightly-20211216 Commit: d458040 Date: 2021-12-16T01:27:31Z
  • OS and platform: Windows 10, Ubuntu 20.04

Additional context


In order to provide proof of the problem after I discovered it, I wrote a unit test for the problem as it occurs via the github.com/arduino/arduino-cli/arduino/libraries.Load entrypoint. It is staged here: 1cb146d

In order to make it as minimal as possible, I used a legacy format library, but @silvanocerza rightly recommended that it would be better to use a modern recursive layout test library for the final form of the test that is introduced into the Arduino CLI code base with the fix for this bug.

Because symlinks pose difficulties for Windows developers, I chose to generate the library on the fly via the test code, rather than adding it as static test data as usual. This test will work fine on Windows as long as it is run as administrator. In the event it is not, the test message for the specific unexpected error handler associated with that situation explains this fact.


Although it was encountered via Arduino Lint, this issue is not limited to that use case. It occurs just the same when using Arduino CLI as a command line tool. I have provided demonstration library and sketch attached to this issue which will cause the bug when used by Arduino CLI from the command line:

SymlinkLoopLib.zip


There is some code in place that is intended to avoid this sort of problem by imposing a hard limit on the depth:

return walkFn(root, info, errors.New("Filesystem bottom is too deep (directory recursion or filesystem really deep): "+root))

And some valuable discussion on the PR that added it: #421

I haven't investigated to learn why that fix is not helping with the issues I found.


The equivalent bug for sketches was fixed by #1353 (attempting to compile a sketch such as SymlinkLoopSketch.zip with this structure now fails: "too many levels of symbolic links" instead of hanging).

I see that the fix was implemented in the github.com/arduino/go-paths-helper module: arduino/go-paths-helper#12

That should pave the way to fixing the issue for libraries as well, but my unit test for github.com/arduino/arduino-cli/arduino/libraries.Load is still failing, so it wasn't fixed as a side effect of the sketch fix.

@per1234 per1234 added criticality: medium Of moderate impact topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Dec 16, 2021
@fstasi fstasi assigned umbynos and unassigned silvanocerza Mar 21, 2022
@umbynos umbynos added this to the Arduino CLI 1.0 milestone Feb 2, 2023
@cmaglie cmaglie assigned MatteoPologruto and unassigned umbynos Mar 17, 2023
@per1234 per1234 added the conclusion: resolved Issue was resolved label May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved criticality: medium Of moderate impact topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
5 participants