]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix content length calculations
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Jul 2021 16:35:00 +0000 (17:35 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Jul 2021 16:35:00 +0000 (17:35 +0100)
src/lua/lua_html.cxx

index 9a562d2fae45881afa89d02ba717d83f89b460cf..2b0f63c02c05cc3e174bca9a4099a40cb55f3214 100644 (file)
@@ -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<rspamd_lua_text *>(lua_newuserdata(L, sizeof(*t)));
                        rspamd_lua_setclass (L, "rspamd{text}", -1);
                        t->start = reinterpret_cast<const char *>(ltag->html->parsed.data()) +