#732702 html2text: segfault because of broken utf8 support

Package:
html2text
Source:
html2text
Description:
advanced HTML to text converter
Submitter:
Dmitry Borisyuk
Date:
2025-08-26 03:27:02 UTC
Severity:
normal
Tags:
#732702#5
Date:
2013-12-20 13:22:04 UTC
From:
To:
Dear Maintainer,
html2text segfaults when converting the attached file twice:

$ html2text 1.html 1.html > 1.txt
Segmentation fault

#732702#10
Date:
2014-11-05 23:26:29 UTC
From:
To:
control: retitle -1 html2text: segfault because of broken utf8 support
control: tags -1 +patch

Dear Maintainers,

I've found that the segfaults reported here are because of integer
overflows and other problems in utf8_* functions in file Area.C
I rewrite them, and it doesn't segfault anymore. Here is the patch:
--- a/Area.C +++ b/Area.C @@ -86,49 +86,29 @@ /* utf_length() and utf_width() * - * Very simplified algorithm of calculating length of UTF-8 - * string. No check for errors. Counting only ASCII bytes and - * leading bytes of UTF-8 multibyte sequences. All bytes like - * 10xxxxxx are dropped. If USE_UTF8 is false then returns - * usual length. --YS + * Easy and secure way: count "continuation" + * (10xxxxxx) bytes and subtract that number. + * If USE_UTF8 is false then returns usual length. */
--- a/Area.C +++ b/Area.C @@ -30,7 +30,7 @@ /***************************************************************************/ - +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> @@ -45,10 +45,14 @@ /* ------------------------------------------------------------------------- */ +static void* alloc_error() { + perror("html2text: error"); abort(); +} + #define malloc_array(type, size)\ -((type *) malloc(sizeof(type) * (size))) +((type *) (malloc(sizeof(type) * (size)) ? : alloc_error())) #define realloc_array(array, type, size) \ -((array) = (type *) realloc((array), sizeof(type) * (size))) +((array) = (type *) (realloc((array), sizeof(type) * (size)) ? : alloc_error())) #define copy_array(from, to, type, count) \ ((void) memcpy((to), (from), (count) * sizeof(type)))
#732702#19
Date:
2025-08-23 04:56:38 UTC
From:
To: