From 9a973977bbba8fda284bbc6eca4991fe0fd1d5ac Mon Sep 17 00:00:00 2001
From: Paul Sokolovsky <pfalcon@users.sourceforge.net>
Date: Sun, 2 Apr 2017 21:20:07 +0300
Subject: [PATCH] py/objstr: Use MICROPY_FULL_CHECKS for range checking when
 constructing bytes.

Split this setting from MICROPY_CPYTHON_COMPAT. The idea is to be able to
keep MICROPY_CPYTHON_COMPAT disabled, but still pass more of regression
testsuite. In particular, this fixes last failing test in basics/ for
Zephyr port.
---
 py/mpconfig.h | 9 +++++++++
 py/objstr.c   | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/py/mpconfig.h b/py/mpconfig.h
index 9c89fc18a..06c19f72b 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -556,6 +556,15 @@ typedef double mp_float_t;
 #define MICROPY_CPYTHON_COMPAT (1)
 #endif
 
+// Perform full checks as done by CPython. Disabling this
+// may produce incorrect results, if incorrect data is fed,
+// but should not lead to MicroPython crashes or similar
+// grave issues (in other words, only user app should be,
+// affected, not system).
+#ifndef MICROPY_FULL_CHECKS
+#define MICROPY_FULL_CHECKS (1)
+#endif
+
 // Whether POSIX-semantics non-blocking streams are supported
 #ifndef MICROPY_STREAMS_NON_BLOCK
 #define MICROPY_STREAMS_NON_BLOCK (0)
diff --git a/py/objstr.c b/py/objstr.c
index 60a26d45b..70de0a693 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -236,7 +236,7 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size
     mp_obj_t item;
     while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
         mp_int_t val = mp_obj_get_int(item);
-        #if MICROPY_CPYTHON_COMPAT
+        #if MICROPY_FULL_CHECKS
         if (val < 0 || val > 255) {
             mp_raise_ValueError("bytes value out of range");
         }
-- 
GitLab