{"record":{"id":"77f1a22053432fb3","repo":"QL-Win/QuickLook","slug":"ds-store-wrong-magic-expected-0x00000001","errorCode":null,"errorMessage":"DS_Store: wrong magic (expected 0x00000001)","messagePattern":"DS_Store: wrong magic \\(expected 0x00000001\\)","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"warning","filePath":"QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/DSStore/DSStoreExtractor.cs","lineNumber":71,"sourceCode":"        public DSStoreAllocator(byte[] data)\n        {\n            _data = data ?? throw new ArgumentNullException(nameof(data));\n            _pos = 0;\n            var (offset, size) = ReadHeader();\n            _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)","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/QL-Win/QuickLook/blob/cb5d9c429c81d9796fac469da2a68efb5626946d/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/DSStore/DSStoreExtractor.cs#L53-L89","documentation":"Thrown by DSStoreAllocator.ReadHeader when the first big-endian uint32 of the .DS_Store data is not 0x00000001. A genuine .DS_Store begins with the version value 1 followed by the 'Bud1' magic; any other first dword means the file is not a .DS_Store or is corrupt.","triggerScenarios":"Calling GetFileNames on a file whose first 4 bytes are not 00 00 00 01: a different binary format, a corrupt .DS_Store, or a file that merely shares the name.","commonSituations":"A file renamed to .DS_Store that is actually something else; a corrupt download from a network share; an alternative .DS_Store writer that uses a different version dword; endianness confusion from a transfer.","solutions":["Validate the first 8 bytes (version 1 + 'Bud1') before parsing.","If the file fails validation, skip it or report it as not a valid .DS_Store.","Re-obtain the .DS_Store from the original macOS volume.","Catch InvalidDataException and return an empty filename list."],"exampleFix":"// before\nvar names = DSStoreExtractor.GetFileNames(path);\n\n// after\nvar data = File.ReadAllBytes(path);\nif (data.Length < 8 || data[0]!=0||data[1]!=0||data[2]!=0||data[3]!=0x01)\n    return new List<string>();\nvar names = DSStoreExtractor.GetFileNames(path);","handlingStrategy":"validation","validationCode":"// Validate the .DS_Store version dword (must be 0x00000001 big-endian).\npublic static bool IsValidDsStoreHeader(string path)\n{\n    var data = File.ReadAllBytes(path);\n    return data.Length >= 8\n        && data[0] == 0 && data[1] == 0 && data[2] == 0 && data[3] == 0x01;\n}","typeGuard":null,"tryCatchPattern":"try { var names = DSStoreExtractor.GetFileNames(path); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"expected 0x00000001\"))\n{\n    // First dword is wrong; file is not a valid .DS_Store.\n}","preventionTips":["Validate the first 4 bytes are 00 00 00 01 before parsing.","Re-obtain the .DS_Store from the original macOS volume if validation 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"}