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

Recursive subsyntax causes detectindent to hang #1247

Closed
xcb-xwii opened this issue Dec 19, 2022 · 1 comment · Fixed by #1253
Closed

Recursive subsyntax causes detectindent to hang #1247

xcb-xwii opened this issue Dec 19, 2022 · 1 comment · Fixed by #1253
Labels
bug Something isn't working plugin

Comments

@xcb-xwii
Copy link
Contributor

-- mod-version:3
local syntax = require "core.syntax"

syntax.add {
  name = "Hang",
  files = { "%.hang$" },
  patterns = {
    { pattern = { "{", "}" }, type = "<T>", syntax = ".hang" },
  },
  symbols = {},
}

Using this syntax file, and opening a corresponding file will cause the editor to hang before giving the following error, if <T> is not comment or string.

[ERROR] /usr/local/share/lite-xl/plugins/detectindent.lua:242: /usr/local/share/lite-xl/core/common.lua:231: stack overflow at /usr/local/share/lite-xl/core/init.lua:1222

stack traceback:
[C]: in for iterator 'for iterator'
/usr/local/share/lite-xl/plugins/detectindent.lua:242: in upvalue 'detect_indent_stat'
/usr/local/share/lite-xl/plugins/detectindent.lua:264: in upvalue 'update_cache'
/usr/local/share/lite-xl/plugins/detectindent.lua:279: in function 'core.doc.new'
/usr/local/share/lite-xl/core/object.lua:54: in function 'core.titleview.__call'
/usr/local/share/lite-xl/core/init.lua:1143: in function 'core.open_doc'
/usr/local/share/lite-xl/plugins/treeview.lua:614: in function </usr/local/share/lite-xl/plugins/treeview.lua:609>
[C]: in function 'xpcall'
/usr/local/share/lite-xl/core/init.lua:1221: in function 'core.try'
/usr/local/share/lite-xl/plugins/treeview.lua:609: in field 'perform'
...(skipping 8 levels)
/usr/local/share/lite-xl/core/keymap.lua:205: in function 'core.keymap.on_key_pressed'
/usr/local/share/lite-xl/core/keymap.lua:246: in function 'core.keymap.on_mouse_pressed'
/usr/local/share/lite-xl/core/init.lua:1246: in upvalue 'on_event'
/usr/local/share/lite-xl/plugins/macro.lua:19: in function 'core.on_event'
[C]: in function 'xpcall'
/usr/local/share/lite-xl/core/init.lua:1221: in function 'core.try'
/usr/local/share/lite-xl/core/init.lua:1306: in function 'core.step'
/usr/local/share/lite-xl/core/init.lua:1384: in function 'core.run'
(...tail calls...)
[string "local core..."]:9: in function <[string "local core..."]:2>
[C]: in function 'xpcall'
[string "local core..."]:2: in main chunk
@Guldoman
Copy link
Member

This is happening because detectindent is recursing through subsyntaxes, but isn't checking for loops.

elseif pattern.syntax then
local subsyntax = type(pattern.syntax) == 'table' and pattern.syntax
or core_syntax.get("file"..pattern.syntax, "")
local sub_comments = get_comment_patterns(subsyntax)
if sub_comments then
for s=1, #sub_comments do
table.insert(comments, sub_comments[s])
end
end
end

I think we can just remove this recursion and only care about what the main syntax defines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working plugin
Projects
None yet
2 participants