summaryrefslogtreecommitdiff
path: root/extensions/source
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2013-02-19 17:10:50 +0200
committerTor Lillqvist <tml@iki.fi>2013-02-19 17:13:51 +0200
commitb8da61acb2bb887a7335a5db82b8b5ae1e0fab69 (patch)
tree4e8751e847fcf8424cd49be37f9f27cc46c6d13a /extensions/source
parentbf46dfdb45b1d6cd99a5c729ee98df89db363225 (diff)
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
Diffstat (limited to 'extensions/source')
-rw-r--r--extensions/source/macosx/spotlight/OOoSpotlightImporter.m21
1 files changed, 16 insertions, 5 deletions
diff --git a/extensions/source/macosx/spotlight/OOoSpotlightImporter.m b/extensions/source/macosx/spotlight/OOoSpotlightImporter.m
index 964b627d5ca2..a4cefc0b03e3 100644
--- a/extensions/source/macosx/spotlight/OOoSpotlightImporter.m
+++ b/extensions/source/macosx/spotlight/OOoSpotlightImporter.m
@@ -208,21 +208,32 @@ static bool areHeadersConsistent(const LocalFileHeader *header, const CentralDir
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];
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);
if (signature == CDIR_END_SIG)
{
- [file seekToFileOffset: (offset - 4)];
+ // Seek back over the CDIR_END_SIG
+ [file seekToFileOffset: offset];
return true;
}
else
- [file seekToFileOffset: (offset - 3)];
+ {
+ // Seek one byte back
+ [file seekToFileOffset: (offset - 1)];
+ }
}
return false;
}