{"record":{"id":"2a52268af97e5799","repo":"QL-Win/QuickLook","slug":"ds-store-wrong-magic-expected-bud1","errorCode":null,"errorMessage":"DS_Store: wrong magic (expected 'Bud1')","messagePattern":"DS_Store: wrong magic \\(expected 'Bud1'\\)","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"warning","filePath":"QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/DSStore/DSStoreExtractor.cs","lineNumber":76,"sourceCode":"            _root = NewBlock(offset, size);\n            ReadOffsets();\n            ReadToc();\n            ReadFreeList();\n        }\n\n        private (uint offset, uint size) ReadHeader()\n        {\n            if (_data.Length < 32)\n                throw new InvalidDataException(\"DS_Store header too short\");\n\n            uint magic1 = ReadUint32BE(_data, (int)_pos);\n            if (magic1 != 1)\n                throw new InvalidDataException(\"DS_Store: wrong magic (expected 0x00000001)\");\n            _pos += 4;\n\n            uint magic = ReadUint32BE(_data, (int)_pos);\n            if (magic != 0x42756431u)\n                throw new InvalidDataException(\"DS_Store: wrong magic (expected 'Bud1')\");\n            _pos += 4;\n\n            uint offset = ReadUint32BE(_data, (int)_pos); _pos += 4;\n            uint size   = ReadUint32BE(_data, (int)_pos); _pos += 4;\n            uint offset2 = ReadUint32BE(_data, (int)_pos);\n            if (offset != offset2)\n                throw new InvalidDataException(\"DS_Store: root-block offset mismatch\");\n            _pos += 4;\n\n            return (offset, size);\n        }\n\n        private DSStoreBlock NewBlock(uint pos, uint size)\n        {\n            if (_data.Length < pos + 4 + size)\n                throw new InvalidDataException(\"DS_Store: not enough data for block\");\n            var buf = new byte[size];\n            Buffer.BlockCopy(_data, (int)pos + 4, buf, 0, (int)size);","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/QL-Win/QuickLook/blob/cb5d9c429c81d9796fac469da2a68efb5626946d/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/DSStore/DSStoreExtractor.cs#L58-L94","documentation":"Thrown by DSStoreAllocator.ReadHeader when bytes 4-7 (big-endian) are not 0x42756431, the ASCII string 'Bud1'. This is the canonical .DS_Store format signature; its absence means the file is not a real .DS_Store B-tree allocator image.","triggerScenarios":"Calling GetFileNames on a file whose bytes 4-7 are not 'Bud1': a non-.DS_Store file, a corrupt file, or a file produced by a tool that does not emit the Bud1 signature.","commonSituations":"Generic binary or text file renamed .DS_Store; corrupt/truncated file from a flaky transfer; a macOS version or third-party tool that writes a different structure.","solutions":["Validate the 'Bud1' signature at offset 4 before parsing.","Skip files that fail the signature check.","Re-copy the file from the original macOS source.","Catch InvalidDataException and return an empty list."],"exampleFix":"// before\nvar names = DSStoreExtractor.GetFileNames(path);\n\n// after\nvar data = File.ReadAllBytes(path);\nif (data.Length < 8 || System.Text.Encoding.ASCII.GetString(data, 4, 4) != \"Bud1\")\n    return new List<string>();\nvar names = DSStoreExtractor.GetFileNames(path);","handlingStrategy":"validation","validationCode":"// Validate the .DS_Store 'Bud1' signature at offset 4.\npublic static bool IsValidDsStoreHeader(string path)\n{\n    var data = File.ReadAllBytes(path);\n    return data.Length >= 8\n        && System.Text.Encoding.ASCII.GetString(data, 4, 4) == \"Bud1\";\n}","typeGuard":null,"tryCatchPattern":"try { var names = DSStoreExtractor.GetFileNames(path); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"Bud1\"))\n{\n    // 'Bud1' signature missing; file is not a valid .DS_Store.\n}","preventionTips":["Validate the 'Bud1' signature at offset 4 before parsing.","Re-copy the .DS_Store from the macOS source if it fails.","Catch InvalidDataException and return an empty list."],"tags":["dsstore","macos","magic-bytes","binary-format","invaliddata","csharp"],"backgroundTag":null,"analyzedSha":"cb5d9c429c81d9796fac469da2a68efb5626946d","analyzedAt":"2026-08-13T11:51:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}