From 47e8abad8456fd3cd46d98241c6bc9ca71cf9368 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 29 Jul 2021 17:35:00 +0100 Subject: [PATCH] [Minor] Fix content length calculations --- src/lua/lua_html.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lua/lua_html.cxx b/src/lua/lua_html.cxx index 9a562d2fa..2b0f63c02 100644 --- a/src/lua/lua_html.cxx +++ b/src/lua/lua_html.cxx @@ -580,8 +580,10 @@ lua_html_tag_get_content (lua_State *L) if (ltag) { auto clen = ltag->tag->get_content_length(); - if (ltag->html && clen && - ltag->html->parsed.size() >= ltag->tag->content_offset + clen) { + if (ltag->html && clen && ltag->html->parsed.size() > ltag->tag->content_offset) { + if (ltag->html->parsed.size() - ltag->tag->content_offset < clen) { + clen = ltag->html->parsed.size() - ltag->tag->content_offset; + } t = static_cast(lua_newuserdata(L, sizeof(*t))); rspamd_lua_setclass (L, "rspamd{text}", -1); t->start = reinterpret_cast(ltag->html->parsed.data()) + -- 2.39.5