{"record":{"id":"4afd4fd9b2dc250f","repo":"QL-Win/QuickLook","slug":"ds-store-header-too-short","errorCode":null,"errorMessage":"DS_Store header too short","messagePattern":"DS_Store header too short","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"warning","filePath":"QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/DSStore/DSStoreExtractor.cs","lineNumber":67,"sourceCode":"        private readonly DSStoreBlock _root;\n        private readonly List<uint> _offsets = [];\n        private readonly Dictionary<string, uint> _toc = new(StringComparer.Ordinal);\n\n        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","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/QL-Win/QuickLook/blob/cb5d9c429c81d9796fac469da2a68efb5626946d/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/DSStore/DSStoreExtractor.cs#L49-L85","documentation":"Thrown by DSStoreAllocator.ReadHeader when the .DS_Store byte data is fewer than 32 bytes. A valid macOS .DS_Store file always has a 32-byte header (magic1, magic 'Bud1', root offset/size, root offset repeat, plus padding), so anything shorter cannot be parsed.","triggerScenarios":"Calling DSStoreExtractor.GetFileNames(path) on an empty file, a near-empty placeholder .DS_Store created by a non-macOS tool, or a truncated/corrupt file under 32 bytes.","commonSituations":"A zero-byte .DS_Store left after a failed sync/copy; a text file renamed .DS_Store; macOS did not finish writing the file; a file from a non-HFS+/APFS filesystem that mimics the name but has no content.","solutions":["Check the file length is >= 32 before parsing.","Skip/ignore .DS_Store files smaller than the header size rather than throwing.","Re-copy the .DS_Store from the macOS source if it was truncated.","Catch InvalidDataException and treat the file as having no stored filenames."],"exampleFix":"// before\nvar names = DSStoreExtractor.GetFileNames(path);\n\n// after\nvar info = new FileInfo(path);\nif (info.Length < 32)\n    return new List<string>(); // not a valid DS_Store, no filenames\nvar names = DSStoreExtractor.GetFileNames(path);","handlingStrategy":"validation","validationCode":"// Skip .DS_Store files smaller than the 32-byte header.\npublic static List<string> SafeGetFileNames(string path)\n{\n    if (new FileInfo(path).Length < 32)\n        return new List<string>();\n    return DSStoreExtractor.GetFileNames(path);\n}","typeGuard":null,"tryCatchPattern":"try { var names = DSStoreExtractor.GetFileNames(path); }\ncatch (InvalidDataException ex) when (ex.Message == \"DS_Store header too short\")\n{\n    // File is too small to be a valid .DS_Store; return empty list.\n}","preventionTips":["Check file length >= 32 before parsing a .DS_Store.","Ignore near-empty placeholder .DS_Store files.","Catch InvalidDataException and degrade to an empty result."],"tags":["dsstore","macos","binary-format","invaliddata","csharp"],"backgroundTag":null,"analyzedSha":"cb5d9c429c81d9796fac469da2a68efb5626946d","analyzedAt":"2026-08-13T11:51:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}