{"record":{"id":"ab57caab3a0d5d83","repo":"QL-Win/QuickLook","slug":"ds-store-block-not-enough-bytes","errorCode":null,"errorMessage":"DS_Store block: not enough bytes","messagePattern":"DS_Store block: not enough bytes","errorType":"exception","errorClass":"EndOfStreamException","httpStatus":null,"severity":"warning","filePath":"QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/DSStore/DSStoreExtractor.cs","lineNumber":201,"sourceCode":"            | ((uint)arr[offset + 1] << 16)\n            | ((uint)arr[offset + 2] << 8)\n            | arr[offset + 3];\n    }\n\n    private sealed class DSStoreBlock(DSStoreAllocator alloc, uint offset, uint size, byte[] data)\n    {\n#pragma warning disable IDE0052\n        private readonly DSStoreAllocator _alloc  = alloc;   // kept for parity / future use\n#pragma warning restore IDE0052\n        private readonly byte[] _data = data;\n\n        public uint Offset { get; } = offset;\n        public uint Size   { get; } = size;\n        public uint Pos    { get; private set; }\n\n        public uint ReadUint32()\n        {\n            if (Size - Pos < 4) throw new EndOfStreamException(\"DS_Store block: not enough bytes\");\n            uint v = ((uint)_data[Pos] << 24)\n                   | ((uint)_data[Pos + 1] << 16)\n                   | ((uint)_data[Pos + 2] << 8)\n                   | _data[Pos + 3];\n            Pos += 4;\n            return v;\n        }\n\n        public byte ReadByte()\n        {\n            if (Size - Pos < 1) throw new EndOfStreamException(\"DS_Store block: not enough bytes\");\n            return _data[Pos++];\n        }\n\n        public byte[] ReadBuf(int length)\n        {\n            if ((int)Size - (int)Pos < length)\n                throw new EndOfStreamException(\"DS_Store block: not enough bytes\");","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/QL-Win/QuickLook/blob/cb5d9c429c81d9796fac469da2a68efb5626946d/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/DSStore/DSStoreExtractor.cs#L183-L219","documentation":"Thrown by DSStoreBlock.ReadUint32 when fewer than 4 bytes remain in the current block (Size - Pos < 4). This EndOfStreamException fires during header/offset/TOC/filename parsing when a block is shorter than the parser expects.","triggerScenarios":"ReadUint32 is called (directly or via ReadToc/ReadOffsets/Traverse/ReadFileName) on a block whose remaining bytes are < 4: corrupt block size in the offset table, truncated block data, or a malformed .DS_Store structure.","commonSituations":"Corrupt .DS_Store where block sizes are inconsistent with actual data; a file from an incompatible macOS version with a subtly different layout; truncated download.","solutions":["Catch EndOfStreamException around GetFileNames and return filenames collected so far.","Re-obtain the .DS_Store from the source.","Add bounds-checking / graceful truncation handling in the traversal loop.","Validate block sizes against the file length during NewBlock."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var names = DSStoreExtractor.GetFileNames(path); }\ncatch (EndOfStreamException ex) when (ex.Message.Contains(\"DS_Store block\"))\n{\n    // Block ran out of bytes during a uint32 read; return partial results.\n    names = new List<string>();\n}","preventionTips":["Catch EndOfStreamException during .DS_Store parsing and return partial filenames.","Re-copy the file from the macOS source.","Add bounds-aware reading in the traversal loop if you control the parser."],"tags":["dsstore","macos","binary-format","corruption","endofstream","csharp"],"backgroundTag":null,"analyzedSha":"cb5d9c429c81d9796fac469da2a68efb5626946d","analyzedAt":"2026-08-13T11:51:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}