diff --git a/src/Base32.php b/src/Base32.php
index b4857c121fd73ddcde6281a1181289eac9e3428a..3ff41562d86ac4392c992517a14ebf73eb410be7 100644
--- a/src/Base32.php
+++ b/src/Base32.php
@@ -196,7 +196,7 @@ abstract class Base32 implements EncoderInterface
             return '';
         }
         if (($srcLen & 7) === 0) {
-            for ($j = 0; $j < 7; ++$j) {
+            for ($j = 0; $j < 7 && $j < $srcLen; ++$j) {
                 if ($encodedString[$srcLen - $j] === '=') {
                     throw new InvalidArgumentException(
                         "decodeNoPadding() doesn't tolerate padding"