You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BinasciiModuleBuiltins.java
// Remove superfluous padding, Java refuses it but CPython ignores it
175
-
intend;
176
-
for (end = dataLen - 1; end >= 0; end--) {
177
-
if (data[end] != '=') {
178
-
break;
174
+
/*
175
+
* The JDK decoder behaves differently in some corner cases. It is more restrictive
176
+
* regarding superfluous padding. On the other hand, it's more permissive when it
177
+
* comes to lack of padding. We compute the expected padding ourselves to cover
178
+
* these two cases manually.
179
+
*/
180
+
// Compute the expected and real padding
181
+
intbase64chars = 0;
182
+
intlastBase64Char = -1;
183
+
intpadding = 0;
184
+
for (inti = 0; i < dataLen; i++) {
185
+
bytec = data[i];
186
+
if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '+' || c == '/') {
187
+
lastBase64Char = i;
188
+
base64chars++;
189
+
padding = 0;
190
+
}
191
+
if (c == '=') {
192
+
padding++;
193
+
}
194
+
}
195
+
intexpectedPadding = 0;
196
+
if (base64chars % 4 == 1) {
197
+
throwPRaiseNode.raiseUncached(this, BinasciiError, "Invalid base64-encoded string: number of data characters (1) cannot be 1 more than a multiple of 4");
0 commit comments