diff --git a/clean/converter/src/map.cpp b/clean/converter/src/map.cpp index 190e93e9..d5e3df72 100644 --- a/clean/converter/src/map.cpp +++ b/clean/converter/src/map.cpp @@ -1327,8 +1327,10 @@ class Loader { for (const Axis& ax : t.axes) { const std::int64_t n = ax.limit >= 0 ? std::min(ax.limit, ax.length) : ax.length; if (n == 0) { + // The tensor reads nothing, but the axes after this one are still checked: the map is validated + // completely before any input is read (an empty axis adds no span). any = false; - break; + continue; } std::int64_t span; if (!checked_mul(ax.stride, n - 1, span) || !checked_add(hi, span, hi)) diff --git a/clean/converter/tests/run_tests5.py b/clean/converter/tests/run_tests5.py index bd9d4afe..5be68f87 100644 --- a/clean/converter/tests/run_tests5.py +++ b/clean/converter/tests/run_tests5.py @@ -429,6 +429,10 @@ def t(m, gname, tname): add("negative base", lambda m: t(m, "G1", "D").update(base=-1)) add("negative stride", lambda m: t(m, "G1", "b")["axes"][1].update(stride=-1)) add("negative limit", lambda m: t(m, "G1", "fe")["axes"][0].update(limit=-1)) + # Issue #54: every axis is checked, also the ones after an empty axis (limit 0): the stride times the index of the + # second axis does not fit 64 bits. + add("huge stride after an empty axis", + lambda m: (t(m, "G1", "b")["axes"][0].update(limit=0), t(m, "G1", "b")["axes"][1].update(stride=9223372036854775807))) add("negative site index", lambda m: t(m, "constants", "SUB")["sites"][0].update(elements=[-1])) add("zero shape dimension", lambda m: t(m, "G1", "D").update(shape=[0])) add("empty shape", lambda m: t(m, "constants", "SUB").update(shape=[]))