{"record":{"id":"e8433f15445a3465","repo":"SeleniumHQ/selenium","slug":"payload-is-not-a-pbzx-stream","errorCode":null,"errorMessage":"Payload is not a pbzx stream","messagePattern":"Payload is not a pbzx stream","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"rust/src/files.rs","lineNumber":253,"sourceCode":"    move_dir(source, target, &options)?;\n    Ok(())\n}\n\nconst PBZX_MAGIC: [u8; 4] = *b\"pbzx\";\nconst XZ_MAGIC: [u8; 6] = [0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00];\n\n/// Decode a `pbzx` stream into the raw cpio archive it wraps.\n///\n/// `pbzx` is Apple's block-based container used for newer `.pkg` Payloads. It\n/// consists of a `pbzx` magic, an 8-byte flags field, then a sequence of chunks\n/// each prefixed by its big-endian decompressed and compressed sizes. A chunk is\n/// xz-compressed unless its bytes are stored verbatim.\nfn decode_pbzx(data: &[u8]) -> Result<Vec<u8>, Error> {\n    let mut cursor = Cursor::new(data);\n    let mut magic = [0u8; 4];\n    cursor.read_exact(&mut magic)?;\n    if magic != PBZX_MAGIC {\n        return Err(anyhow!(\"Payload is not a pbzx stream\"));\n    }\n    // The 8-byte flags field is not needed to walk the chunks.\n    cursor.read_exact(&mut [0u8; 8])?;\n\n    let mut output = Vec::new();\n    let mut sizes = [0u8; 8];\n    loop {\n        match cursor.read_exact(&mut sizes) {\n            Ok(()) => {}\n            Err(err) if err.kind() == io::ErrorKind::UnexpectedEof => break,\n            Err(err) => return Err(err.into()),\n        }\n        // Decompressed size is recorded but not required to read the chunk.\n        cursor.read_exact(&mut sizes)?;\n        let compressed_size = u64::from_be_bytes(sizes) as usize;\n        let mut chunk = vec![0u8; compressed_size];\n        cursor.read_exact(&mut chunk)?;\n","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rust/src/files.rs#L235-L271","documentation":"Raised by decode_pbzx() (files.rs:253) when the first 4 bytes of a .pkg Payload are not the ASCII magic 'pbzx'. Apple's modern .pkg Payload files are pbzx-wrapped cpio archives; a missing magic means the file is either an older format, corrupt, or not a Payload at all. decode_pbzx is called during macOS .pkg extraction.","triggerScenarios":"uncompress_pkg reads the Payload file and passes its bytes to decode_pbzx. cursor.read_exact(&mut magic) succeeds but magic != PBZX_MAGIC ('pbzx'). Typical when the .pkg uses a legacy uncompressed cpio Payload, the file is truncated, or a non-Payload was read.","commonSituations":"An older .pkg whose Payload is raw cpio (no pbzx wrapper); a corrupted/truncated download; the wrong file inside the .pkg was selected as Payload; a third-party packaging tool emits a different Payload format.","solutions":["Verify the .pkg is a modern Apple installer (use `xar -tf <pkg>` to list contents).","Re-download the driver .pkg to rule out truncation.","If the Payload is raw cpio, extend decode_pbzx to fall back to direct cpio handling.","Run the extraction on genuine macOS where pkgutil handles all formats."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Bash: verify the .pkg Payload is a pbzx stream before decode\nPAYLOAD=$(xar -tf \"$PKG\" | grep -i Payload | head -1)\nxar -xf \"$PKG\" \"$PAYLOAD\" 2>/dev/null\nif [ \"$(head -c4 \"$PAYLOAD\" 2>/dev/null)\" != \"pbzx\" ]; then\n  echo \"Payload is not pbzx; may be legacy cpio or corrupt\"; exit 1\nfi","typeGuard":null,"tryCatchPattern":"match decode_pbzx(&data) {\n    Ok(cpio) => cpio,\n    Err(e) if e.to_string().contains(\"not a pbzx stream\") => {\n        eprintln!(\"Payload magic mismatch; re-download .pkg or handle legacy cpio\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Verify .pkg integrity with `xar -tf` before extraction.","Re-download truncated .pkg files.","Run pkg extraction on genuine macOS where pkgutil handles all formats."],"tags":["rust","selenium-manager","archive","macos","pkg","pbzx"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}