aboutsummaryrefslogtreecommitdiff
path: root/python/google/protobuf/internal/decoder.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/google/protobuf/internal/decoder.py')
-rwxr-xr-xpython/google/protobuf/internal/decoder.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/python/google/protobuf/internal/decoder.py b/python/google/protobuf/internal/decoder.py
index 938f6293d..d2ec4f7b7 100755
--- a/python/google/protobuf/internal/decoder.py
+++ b/python/google/protobuf/internal/decoder.py
@@ -83,7 +83,9 @@ __author__ = 'kenton@google.com (Kenton Varda)'
import struct
import six
+import sys
+_UCS2_MAXUNICODE = 65535
if six.PY3:
long = int
else:
@@ -550,7 +552,8 @@ def StringDecoder(field_number, is_repeated, is_packed, key, new_default,
e.reason = '%s in field: %s' % (e, key.full_name)
raise
- if is_strict_utf8 and six.PY2:
+ if is_strict_utf8 and six.PY2 and sys.maxunicode > _UCS2_MAXUNICODE:
+ # Only do the check for python2 ucs4 when is_strict_utf8 enabled
if _SURROGATE_PATTERN.search(value):
reason = ('String field %s contains invalid UTF-8 data when parsing'
'a protocol buffer: surrogates not allowed. Use'