Skip to content

Hang on symlink loop in library #1593

Closed
@per1234

Description

@per1234

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.

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions