{"record":{"id":"1d644979966489d2","repo":"tauri-apps/tauri","slug":"failed-to-convert-base64-to-string","errorCode":null,"errorMessage":"failed to convert base64 to string","messagePattern":"failed to convert base64 to string","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri-macos-sign/src/lib.rs","lineNumber":339,"sourceCode":"          self\n            .arg(\"--key-id\")\n            .arg(key_id)\n            .arg(\"--key\")\n            .arg(key_path)\n            .arg(\"--issuer\")\n            .arg(issuer),\n        )\n      }\n    }\n  }\n}\n\nfn decode_base64(base64_input: &OsStr, out_path: &Path) -> Result<()> {\n  use base64::Engine;\n\n  let input = base64_input\n    .to_str()\n    .expect(\"failed to convert base64 to string\");\n\n  // strip whitespace before decoding\n  let cleaned: String = input.chars().filter(|c| !c.is_ascii_whitespace()).collect();\n\n  let decoded = base64::engine::general_purpose::STANDARD\n    .decode(&cleaned)\n    .map_err(Error::Base64Decode)?;\n\n  std::fs::write(out_path, &decoded).map_err(|error| Error::Fs {\n    context: \"failed to write decoded certificate\",\n    path: out_path.to_path_buf(),\n    error,\n  })?;\n\n  Ok(())\n}\n\nfn assert_command(","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri-macos-sign/src/lib.rs#L321-L357","documentation":"decode_base64 converts its OsStr input to &str and panics if the base64 credential blob is not valid UTF-8. This is used for decoding Apple notarization credentials (e.g. key content) supplied as base64, so the library assumes callers pass well-formed base64 text.","triggerScenarios":"Passing an AppleNotarizationCredentials field (such as key or issuer content) as an OsStr containing non-UTF-8 bytes into the credential-decoding path.","commonSituations":"Reading a base64 credential from a file opened in binary mode with corrupted bytes, or copying a key with terminal/encoding munging on Windows or unusual locales.","solutions":["Re-export the base64 credential ensuring it is plain ASCII text","Re-encode the source key (e.g. base64 the .p8 file again) and store it as UTF-8 text","Read credentials from files using String::from_utf8 validation before use"],"exampleFix":"// before\nlet raw = std::fs::read(\"key.b64\").unwrap();\nnotarize(path, &creds_from_raw_bytes(raw), true).unwrap();\n// after\nlet raw = std::fs::read(\"key.b64\").unwrap();\nlet text = String::from_utf8(raw).expect(\"credential must be UTF-8 base64\");\nnotarize(path, &creds_from_text(text), true).unwrap();","handlingStrategy":"validation","validationCode":"let bytes = std::fs::read(\"key.b64\")?;\nlet text = String::from_utf8(bytes).expect(\"base64 credential must be UTF-8\");\nassert!(!text.trim().is_empty());","typeGuard":"fn is_utf8_osstr(s: &OsStr) -> bool { s.to_str().is_some() }","tryCatchPattern":null,"preventionTips":["Store base64 credentials as plain-text files only","Re-export credentials if a transfer mangled encoding","Validate credentials with String::from_utf8 before passing to notarize"],"tags":["macos","notarization","base64","utf-8"],"backgroundTag":"invalid-argument-format","analyzedSha":"460ec35447493200d64290dd7f015d5a91d0fd58","analyzedAt":"2026-09-18T23:55:51.277Z","contentChangedAt":"2026-09-18T23:55:51.277Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}