Index: src/OFZIPArchive.m ================================================================== --- src/OFZIPArchive.m +++ src/OFZIPArchive.m @@ -83,45 +83,10 @@ - initWithArchiveFile: (OFString*)path offset: (off_t)offset localFileHeader: (OFZIPArchive_LocalFileHeader*)localFileHeader; @end -void -of_zip_archive_find_extra_field(OFDataArray *extraField, uint16_t tag, - uint8_t **data, uint16_t *size) -{ - uint8_t *bytes; - size_t i, count; - - bytes = [extraField items]; - count = [extraField count]; - - for (i = 0; i < count;) { - uint16_t currentTag, currentSize; - - if (i + 3 >= count) - @throw [OFInvalidFormatException exception]; - - currentTag = (bytes[i + 1] << 8) | bytes[i]; - currentSize = (bytes[i + 3] << 8) | bytes[i + 2]; - - if (i + 3 + currentSize >= count) - @throw [OFInvalidFormatException exception]; - - if (currentTag == tag) { - *data = bytes + i + 4; - *size = currentSize; - return; - } - - i += 4 + currentSize; - } - - *data = NULL; - *size = 0; -} - uint32_t of_zip_archive_read_field32(uint8_t **data, uint16_t *size) { uint32_t field = 0; uint_fast8_t i; @@ -428,11 +393,11 @@ _fileName = [[file readStringWithLength: fileNameLength encoding: encoding] copy]; _extraField = [[file readDataArrayWithCount: extraFieldLength] retain]; - of_zip_archive_find_extra_field(_extraField, 0x0001, + of_zip_archive_entry_find_extra_field(_extraField, 0x0001, &ZIP64, &ZIP64Size); if (ZIP64 != NULL) { if (_uncompressedSize == 0xFFFFFFFF) _uncompressedSize = of_zip_archive_read_field64( Index: src/OFZIPArchiveEntry.h ================================================================== --- src/OFZIPArchiveEntry.h +++ src/OFZIPArchiveEntry.h @@ -14,11 +14,11 @@ * file. */ #import "OFObject.h" -#include +/*! @file */ @class OFString; @class OFDataArray; @class OFFile; @class OFDate; @@ -100,5 +100,22 @@ * * @return The extra field of the entry */ - (OFDataArray*)extraField; @end + +#ifdef __cplusplus +extern "C" { +#endif +/*! + * @brief Gets a pointer to and the size of the extra field with the specified + * tag. + * + * @param data A pointer to a pointer that should be set to the start of the + * extra field with the specified tag + * @param size A pointer to an uint16_t that should be set to the size + */ +extern void of_zip_archive_entry_find_extra_field(OFDataArray *extraField, + uint16_t tag, uint8_t **data, uint16_t *size); +#ifdef __cplusplus +} +#endif Index: src/OFZIPArchiveEntry.m ================================================================== --- src/OFZIPArchiveEntry.m +++ src/OFZIPArchiveEntry.m @@ -27,14 +27,47 @@ #import "macros.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" -extern void of_zip_archive_find_extra_field(OFDataArray*, uint16_t, uint8_t**, - uint16_t*); extern uint32_t of_zip_archive_read_field32(uint8_t**, uint16_t*); extern uint64_t of_zip_archive_read_field64(uint8_t**, uint16_t*); + +void +of_zip_archive_entry_find_extra_field(OFDataArray *extraField, uint16_t tag, + uint8_t **data, uint16_t *size) +{ + uint8_t *bytes; + size_t i, count; + + bytes = [extraField items]; + count = [extraField count]; + + for (i = 0; i < count;) { + uint16_t currentTag, currentSize; + + if (i + 3 >= count) + @throw [OFInvalidFormatException exception]; + + currentTag = (bytes[i + 1] << 8) | bytes[i]; + currentSize = (bytes[i + 3] << 8) | bytes[i + 2]; + + if (i + 3 + currentSize >= count) + @throw [OFInvalidFormatException exception]; + + if (currentTag == tag) { + *data = bytes + i + 4; + *size = currentSize; + return; + } + + i += 4 + currentSize; + } + + *data = NULL; + *size = 0; +} @implementation OFZIPArchiveEntry - (instancetype)OF_initWithFile: (OFFile*)file { self = [super init]; @@ -75,11 +108,11 @@ _extraField = [[file readDataArrayWithCount: extraFieldLength] retain]; _fileComment = [[file readStringWithLength: fileCommentLength encoding: encoding] copy]; - of_zip_archive_find_extra_field(_extraField, 0x0001, + of_zip_archive_entry_find_extra_field(_extraField, 0x0001, &ZIP64, &ZIP64Size); if (ZIP64 != NULL) { if (_uncompressedSize == 0xFFFFFFFF) _uncompressedSize = of_zip_archive_read_field64(