QL-Win/QuickLook · warning · InvalidDataException
DS_Store: wrong magic (expected 0x00000001)
Error message
DS_Store: wrong magic (expected 0x00000001)
What it means
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.
Source
Thrown at QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/DSStore/DSStoreExtractor.cs:71
public DSStoreAllocator(byte[] data)
{
_data = data ?? throw new ArgumentNullException(nameof(data));
_pos = 0;
var (offset, size) = ReadHeader();
_root = NewBlock(offset, size);
ReadOffsets();
ReadToc();
ReadFreeList();
}
private (uint offset, uint size) ReadHeader()
{
if (_data.Length < 32)
throw new InvalidDataException("DS_Store header too short");
uint magic1 = ReadUint32BE(_data, (int)_pos);
if (magic1 != 1)
throw new InvalidDataException("DS_Store: wrong magic (expected 0x00000001)");
_pos += 4;
uint magic = ReadUint32BE(_data, (int)_pos);
if (magic != 0x42756431u)
throw new InvalidDataException("DS_Store: wrong magic (expected 'Bud1')");
_pos += 4;
uint offset = ReadUint32BE(_data, (int)_pos); _pos += 4;
uint size = ReadUint32BE(_data, (int)_pos); _pos += 4;
uint offset2 = ReadUint32BE(_data, (int)_pos);
if (offset != offset2)
throw new InvalidDataException("DS_Store: root-block offset mismatch");
_pos += 4;
return (offset, size);
}
private DSStoreBlock NewBlock(uint pos, uint size)View on GitHub (pinned to cb5d9c429c)
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.
Example fix
// before
var names = DSStoreExtractor.GetFileNames(path);
// after
var data = File.ReadAllBytes(path);
if (data.Length < 8 || data[0]!=0||data[1]!=0||data[2]!=0||data[3]!=0x01)
return new List<string>();
var names = DSStoreExtractor.GetFileNames(path); Defensive patterns
Strategy: validation
Validate before calling
// Validate the .DS_Store version dword (must be 0x00000001 big-endian).
public static bool IsValidDsStoreHeader(string path)
{
var data = File.ReadAllBytes(path);
return data.Length >= 8
&& data[0] == 0 && data[1] == 0 && data[2] == 0 && data[3] == 0x01;
} Try / catch
try { var names = DSStoreExtractor.GetFileNames(path); }
catch (InvalidDataException ex) when (ex.Message.Contains("expected 0x00000001"))
{
// First dword is wrong; file is not a valid .DS_Store.
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- DS_Store: wrong magic (expected 'Bud1')
- DS_Store header too short
- DS_Store: root-block offset mismatch
- DS_Store: not enough data for block
- DS_Store: block id out of range
AI-assisted analysis of QL-Win/QuickLook@cb5d9c429c (2026-08-13).
Data as JSON: /api/errors/77f1a22053432fb3.
Report an issue: GitHub.