summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2013-02-19 17:10:50 +0200
committerFridrich Strba <fridrich@documentfoundation.org>2013-02-25 12:11:52 +0000
commitf04accd329a4fdea0941b24845e3c74b59afae62 (patch)
tree3a51fcb1526a554e48f520f45273908fce40a7a6
parente5439ccf15308abf73833b927443057c5979a37a (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. (cherry picked from commit b8da61acb2bb887a7335a5db82b8b5ae1e0fab69) (cherry picked from commit 95e6a0885e65cc57b11719cc0658be9d8b78fba9) Change-Id: I9adc65d1821d0920ce3a39d05697557c4303ff68 Reviewed-on: https://gerrit.libreoffice.org/2266 Reviewed-by: Michael Stahl <mstahl@redhat.com> Reviewed-by: Norbert Thiebaud <nthiebaud@gmail.com> Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org> Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
-rw-r--r--extensions/source/macosx/spotlight/OOoSpotlightImporter.m27
1 files changed, 22 insertions, 5 deletions
diff --git a/extensions/source/macosx/spotlight/OOoSpotlightImporter.m b/extensions/source/macosx/spotlight/OOoSpotlightImporter.m
index 964b627d5ca2..3a72d5337051 100644
--- a/extensions/source/macosx/spotlight/OOoSpotlightImporter.m
+++ b/extensions/source/macosx/spotlight/OOoSpotlightImporter.m
@@ -208,21 +208,38 @@ 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 limit;
+ if (fileLength > 1024)
+ limit = fileLength - 1024;
+ else
+ limit = 0;
+
+ unsigned long long offset;
+ while ((offset = [file offsetInFile]) > limit)
{
- 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;
}