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)))