Jakub Wilk <address@hidden> writes:
> The attached (slightly corrupted) MO file crashes msgunfmt:
>
> $ msgunfmt messages.mo
> Segmentation fault
Thanks for the report. It seems like a long standing issue (I can
reproduce it even with 0.17).
> I suspect there's a integer overflow somewhere.
Yes. I'm attaching a patch and a test-case.
Regards,
--
Daiki Ueno
>From 2a760b57161a2b4769e0b1c74db243b213733ef3 Mon Sep 17 00:00:00 2001
From: Daiki Ueno <address@hidden>
Date: Tue, 18 Nov 2014 12:11:22 +0900
Subject: [PATCH 1/2] read-mo: Check size_t overflow
* read-mo.c: Include "xsize.h".
(get_string): Use xsum3 to avoid overflow, when checking length
and offset fields.
Reported by Jakub Wilk at:
<https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=769901>.
---
gettext-tools/src/ChangeLog | 8 ++++++++
gettext-tools/src/read-mo.c | 4 +++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog
index d392ba7..e250ae1 100644
--- a/gettext-tools/src/ChangeLog
+++ b/gettext-tools/src/ChangeLog
@@ -1,3 +1,11 @@
+2014-11-18 Daiki Ueno <address@hidden>
+
+ * read-mo.c: Include "xsize.h".
+ (get_string): Use xsum3 to avoid overflow, when checking length
+ and offset fields.
+ Reported by Jakub Wilk at:
+ <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=769901>.
+
2014-10-28 Daiki Ueno <address@hidden>
xgettext: Allow plural extraction from a single argument function
diff --git a/gettext-tools/src/read-mo.c b/gettext-tools/src/read-mo.c
index 9e0220c..c867236 100644
--- a/gettext-tools/src/read-mo.c
+++ b/gettext-tools/src/read-mo.c
@@ -38,6 +38,7 @@
#include "message.h"
#include "format.h"
#include "gettext.h"
+#include "xsize.h"
#define _(str) gettext (str)
@@ -121,8 +122,9 @@ get_string (const struct binary_mo_file *bfp, size_t
offset, size_t *lengthp)
/* See 'struct string_desc'. */
nls_uint32 s_length = get_uint32 (bfp, offset);
nls_uint32 s_offset = get_uint32 (bfp, offset + 4);
+ size_t s_end = xsum3 (s_offset, s_length, 1);
- if (s_offset + s_length + 1 > bfp->size)
+ if (size_overflow_p (s_end) || s_end > bfp->size)
error (EXIT_FAILURE, 0, _("file \"%s\" is truncated"), bfp->filename);
if (bfp->data[s_offset + s_length] != '\0')
error (EXIT_FAILURE, 0,
--
2.1.0