Closed pteichman closed 7 years ago
Once I took a look at the code it was clear that this is an O(n*m) problem and so maybe not overtly fixable, but I think the suggestion to add cancellation to the API still makes sense.
Finally I got some time to fix this issue. Thanks for the report and your patient.
This is also documented somewhat over at gojsondiff (https://github.com/yudai/gojsondiff/issues/9 where maybe some API changes can help), but the core issue is here in golcs.
It's possible to construct strings of around 10000 bytes (on my machine at least) that cause lcs.Length() to run indefinitely. I've added a test case over here: https://github.com/pteichman/golcs/tree/infinite-hang
Is your sense that this could be improved with a different algorithm in golcs, or should the API be extended to allow cancellation if a deadline is exceeded (using, say, context.Context)?