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

Detect license hang for a long time #48

Open
iacore opened this issue Dec 31, 2021 · 1 comment
Open

Detect license hang for a long time #48

iacore opened this issue Dec 31, 2021 · 1 comment
Labels
research Extra attention is needed

Comments

@iacore
Copy link

iacore commented Dec 31, 2021

How to reproduce:

  1. Create a new directory
  2. Download https://gist.github.com/locriacyber/100837526561cc6b7f508868cfd33780 as LICENSE
  3. zig init-exe
  4. zigmod init

The process will hang for a long time.

@iacore
Copy link
Author

iacore commented Dec 31, 2021

I found the reason. Zig detect license gets the levenstein distance of the entire file (1KB).

pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {
    var min: ?usize = null;
    var ind: ?usize = null;

    for (licenses.spdx) |item, i| {
        const distance = try leven.leven(u8, alloc, license_src, item[1], min);

        if (min == null or distance < min.?) {
            min = distance;
            ind = i;
        }
    }

    return licenses.spdx[ind.?][0];
}

@nektro nektro added the research Extra attention is needed label Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
research Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants