Fix scan for central directory end signature in ODF in Spotlight importer

Once this was fixed it seems to work nicely. Add keywords in
File:Properties and they show up in Finder's Properties, and Spotlight
finds text from the document contents.

Change-Id: I203576a5a7e53ca3485b0a82f0c6d06122f361d1
This commit is contained in:
Tor Lillqvist
2013-02-19 17:10:50 +02:00
parent bf46dfdb45
commit b8da61acb2

View File

@@ -208,21 +208,32 @@ static bool areHeadersConsistent(const LocalFileHeader *header, const CentralDir
static bool findCentralDirectoryEnd(NSFileHandle *file) static bool findCentralDirectoryEnd(NSFileHandle *file)
{ {
// Assume the cdir end is in the last 1024 bytes
// Scan backward from end of file for the end signature
[file seekToEndOfFile]; [file seekToEndOfFile];
unsigned long long fileLength = [file offsetInFile]; unsigned long long fileLength = [file offsetInFile];
[file seekToFileOffset: 0];
while ([file offsetInFile] < fileLength) if (fileLength < 10)
return false;
[file seekToFileOffset: (fileLength - 4)];
unsigned long long offset;
while ((offset = [file offsetInFile]) > 0 && offset >= fileLength - 1024)
{ {
unsigned long long offset = [file offsetInFile];
unsigned signature = readInt(file); unsigned signature = readInt(file);
if (signature == CDIR_END_SIG) if (signature == CDIR_END_SIG)
{ {
[file seekToFileOffset: (offset - 4)]; // Seek back over the CDIR_END_SIG
[file seekToFileOffset: offset];
return true; return true;
} }
else else
[file seekToFileOffset: (offset - 3)]; {
// Seek one byte back
[file seekToFileOffset: (offset - 1)];
}
} }
return false; return false;
} }