diff --git a/gedit/gedit-document-output-stream.c b/gedit/gedit-document-output-stream.c
index fd3bf27..1c58f77 100644
--- a/gedit/gedit-document-output-stream.c
+++ b/gedit/gedit-document-output-stream.c
@@ -356,6 +356,26 @@ try_convert (GCharsetConverter *converter,
 	return ret;
 }
 
+static gsize
+count_nulls (const char *inbuf,
+             gsize       inbuf_size)
+{
+	gsize count;
+	const char *ptr;
+
+	count = 0;
+	ptr = inbuf;
+	while (ptr < (inbuf + inbuf_size)) {
+		ptr = memchr(ptr, '\0', inbuf_size - (ptr - inbuf));
+		if (ptr == NULL)
+			break;
+		ptr++;
+		count++;
+	}
+
+	return count;
+}
+
 static GCharsetConverter *
 guess_encoding (GeditDocumentOutputStream *stream,
 		const void                *inbuf,
@@ -400,9 +420,13 @@ guess_encoding (GeditDocumentOutputStream *stream,
 
 		if (enc == gedit_encoding_get_utf8 ())
 		{
-			gsize remainder;
+			gsize remainder, nulls;
 			const gchar *end;
-			
+
+			nulls = count_nulls(inbuf, inbuf_size);
+			if (nulls > 5)
+				continue;
+
 			if (g_utf8_validate (inbuf, inbuf_size, &end) ||
 			    stream->priv->use_first)
 			{
