commit 47e8aba: [Minor] Fix content length calculations

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Jul 29 16:56:05 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-07-29 17:35:00 +0100
URL: https://github.com/rspamd/rspamd/commit/47e8abad8456fd3cd46d98241c6bc9ca71cf9368

[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<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()) +


More information about the Commits mailing list