{"record":{"id":"715faef226f3caec","repo":"zloirock/core-js","slug":"missing-padding","errorCode":null,"errorMessage":"Missing padding","messagePattern":"Missing padding","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"packages/core-js/internals/uint8-from-base64.js","lineNumber":106,"sourceCode":"  var written = 0;\n  var read = 0;\n  var chunk = '';\n  var index = 0;\n\n  if (maxLength) while (true) {\n    index = skipAsciiWhitespace(string, index);\n    if (index === stringLength) {\n      if (chunk.length > 0) {\n        if (lastChunkHandling === 'stop-before-partial') {\n          break;\n        }\n        if (lastChunkHandling === 'loose') {\n          if (chunk.length === 1) {\n            throw new SyntaxError('Malformed padding: exactly one additional character');\n          }\n          written = writeBytes(bytes, decodeBase64Chunk(chunk, alphabet, false), written);\n        } else {\n          throw new SyntaxError('Missing padding');\n        }\n      }\n      read = stringLength;\n      break;\n    }\n    var chr = at(string, index);\n    ++index;\n    if (chr === '=') {\n      if (chunk.length < 2) {\n        throw new SyntaxError('Padding is too early');\n      }\n      index = skipAsciiWhitespace(string, index);\n      if (chunk.length === 2) {\n        if (index === stringLength) {\n          if (lastChunkHandling === 'stop-before-partial') {\n            break;\n          }\n          throw new SyntaxError('Malformed padding: only one =');","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/internals/uint8-from-base64.js#L88-L124","documentation":"With lastChunkHandling 'strict', Uint8Array.fromBase64 requires the final chunk to be properly '=' padded. If the input ends with an unpadded 2- or 3-character chunk, the polyfill throws this SyntaxError ('Missing padding') — strict mode accepts only canonical, fully padded base64 or complete 4-char groups.","triggerScenarios":"`Uint8Array.fromBase64('QUI', { lastChunkHandling: 'strict' })` — the 3-char tail lacks '='; likewise a 2-char tail like 'QQ' without '==' under strict mode.","commonSituations":"URL-safe/padless base64 (as used in JWTs) fed into strict fromBase64, base64url encoders that omit '=' by convention, or piping JWT segments / padded-less encoder output into a strict decoder.","solutions":["Use lastChunkHandling: 'loose' (default) or 'stop-before-partial' for padless input.","Restore '=' padding before decoding: pad to a multiple of 4 with '='.","Use a base64url-aware decoder (Uint8Array.fromBase64 with alphabet: 'base64url') and non-strict mode for JWT-style data.","Have the encoder emit standard padded base64."],"exampleFix":"// before\nUint8Array.fromBase64('QUI', { lastChunkHandling: 'strict' }); // SyntaxError: Missing padding\n// after\nlet s = 'QUI';\ns += '='.repeat((4 - (s.length % 4)) % 4); // 'QUI='\nUint8Array.fromBase64(s, { lastChunkHandling: 'strict' });","handlingStrategy":"validation","validationCode":"function ensurePadded(b64) {\n  const s = b64.replace(/\\s/g, '');\n  return s + '='.repeat((4 - (s.length % 4)) % 4);\n}\nconst padded = ensurePadded(input);","typeGuard":"function isPaddedOrComplete(s) { const n = s.replace(/\\s/g,'').length % 4; return n === 0 || n === 1 ? n === 0 : true; }","tryCatchPattern":"try {\n  bytes = Uint8Array.fromBase64(b64, { lastChunkHandling: 'strict' });\n} catch (e) {\n  if (e instanceof SyntaxError && e.message === 'Missing padding') {\n    const s = b64.replace(/\\s/g, '') + '='.repeat((4 - (b64.replace(/\\s/g, '').length % 4)) % 4);\n    bytes = Uint8Array.fromBase64(s, { lastChunkHandling: 'strict' });\n  } else throw e;\n}","preventionTips":["Don't feed padless base64 (JWT segments) into strict mode.","Normalize input to padded base64 before strict decoding.","Set alphabet: 'base64url' plus non-strict mode for URL-safe input."],"tags":["core-js","base64","padding","syntaxerror"],"backgroundTag":"base64-missing-padding","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}