{"record":{"id":"992152b0a3149096","repo":"zloirock/core-js","slug":"malformed-padding-only-one","errorCode":null,"errorMessage":"Malformed padding: only one =","messagePattern":"Malformed padding: only one =","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"packages/core-js/internals/uint8-from-base64.js","lineNumber":124,"sourceCode":"          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 =');\n        }\n        if (at(string, index) === '=') {\n          ++index;\n          index = skipAsciiWhitespace(string, index);\n        }\n      }\n      if (index < stringLength) {\n        throw new SyntaxError('Unexpected character after padding');\n      }\n      written = writeBytes(bytes, decodeBase64Chunk(chunk, alphabet, lastChunkHandling === 'strict'), written);\n      read = stringLength;\n      break;\n    }\n    if (!hasOwn(alphabet, chr)) {\n      throw new SyntaxError('Unexpected character');\n    }\n    var remainingBytes = maxLength - written;\n    if (remainingBytes === 1 && chunk.length === 2 || remainingBytes === 2 && chunk.length === 3) {","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/internals/uint8-from-base64.js#L106-L142","documentation":"In a 4-character chunk encoding 2 bytes, the base64 spec requires the second padding '=' to follow the first. If the chunk has exactly 2 characters of data and the remaining input ends (or does not contain a second '=') without providing the second '=', fromBase64 throws this SyntaxError because a 2-byte chunk must be terminated by '=='.","triggerScenarios":"Uint8Array.fromBase64('AB=') or fromBase64('AB=  ') (trailing whitespace is skipped, then the string ends) — a chunk with chunk.length === 2 followed by '=' only once, when lastChunkHandling is not 'stop-before-partial'.","commonSituations":"Base64 strings truncated in transit (e.g. by fixed-width buffers or DB column limits), copy/paste dropping the final character, or strings produced by encoders emitting only one '=' for 2-byte final chunks.","solutions":["Ensure every 2-byte final chunk ends with '==' — append the missing '=' (e.g. 'AB=' → 'AB==').","Verify the string wasn't truncated by a length limit; compare with the expected encoded length ((n+2)/3*4 rounded up).","Pass lastChunkHandling: 'loose' if you intentionally accept non-standard single-padded input only where supported.","Use lastChunkHandling: 'stop-before-partial' if you want to stop at an incomplete final chunk instead of throwing."],"exampleFix":"// before\nUint8Array.fromBase64('QUJD QQ=', { lastChunkHandling: 'strict' }); // Malformed padding: only one =\n// after\nconst fixed = raw.endsWith('=') && !raw.endsWith('==') ? raw + '=' : raw;\nUint8Array.fromBase64(fixed, { lastChunkHandling: 'strict' });","handlingStrategy":"validation","validationCode":"function hasCompletePadding(s) {\n  const compact = s.replace(/[\\t\\n\\f\\r ]/g, '');\n  const rem = compact.length % 4;\n  if (rem === 0) return true;\n  if (rem === 2) return compact.endsWith('==');\n  if (rem === 3) return compact.endsWith('=');\n  return false; // rem === 1 is always invalid\n}","typeGuard":"function isPaddedBase64(s) {\n  if (typeof s !== 'string') return false;\n  const c = s.replace(/[\\t\\n\\f\\r ]/g, '');\n  return c.length % 4 !== 1;\n}","tryCatchPattern":"try {\n  const bytes = Uint8Array.fromBase64(input);\n} catch (e) {\n  if (e instanceof SyntaxError && e.message.includes('Malformed padding')) {\n    throw new TypeError('Base64 requires \"==\" for 2-byte final chunks');\n  }\n  throw e;\n}","preventionTips":["Check that remainder-2 strings end with '==' before decoding.","Watch for fixed-length truncation in transport/storage that drops trailing '='.","Use lastChunkHandling: 'stop-before-partial' when partial final chunks are expected.","Test round-trips: encode(decode(s)) === normalized(s)."],"tags":["base64","syntax-error","padding","validation"],"backgroundTag":"malformed-base64-padding","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}