diff --git a/include/sqsh_extract_private.h b/include/sqsh_extract_private.h index f53334809..173966639 100644 --- a/include/sqsh_extract_private.h +++ b/include/sqsh_extract_private.h @@ -96,6 +96,18 @@ struct SqshExtractor { size_t block_size; }; +/** + * @internal + * @memberof SqshExtractor + * @brief Returns the extractor implementation for a given id. + * + * @param[in] id The id of the compression algorithm to use. + * + * @return pointer to the extractor implementation or NULL if the extraction + * algorithm is not supported. + */ +const struct SqshExtractorImpl *sqsh__extractor_impl_from_id(int id); + /** * @internal * @memberof SqshExtractor diff --git a/lib/extract/extract_manager.c b/lib/extract/extract_manager.c index 13c1510c0..f78f63f14 100644 --- a/lib/extract/extract_manager.c +++ b/lib/extract/extract_manager.c @@ -89,6 +89,11 @@ sqsh__extract_manager_init( SQSH_CONFIG_DEFAULT(config->compression_lru_size, 128); const struct SqshSuperblock *superblock = sqsh_archive_superblock(archive); + if (sqsh__extractor_impl_from_id(sqsh_superblock_compression_id(superblock)) == + NULL) { + return -SQSH_ERROR_COMPRESSION_UNSUPPORTED; + } + if (size == 0) { return -SQSH_ERROR_SIZE_MISMATCH; } diff --git a/lib/extract/extractor.c b/lib/extract/extractor.c index 7b69f2dfb..0f2b401dd 100644 --- a/lib/extract/extractor.c +++ b/lib/extract/extractor.c @@ -41,7 +41,7 @@ const struct SqshExtractorImpl *const __attribute__((weak)) sqsh__impl_lzo = NULL; const struct SqshExtractorImpl * -extractor_by_id(int id) { +sqsh__extractor_impl_from_id(int id) { switch ((enum SqshSuperblockCompressionId)id) { case SQSH_COMPRESSION_GZIP: return sqsh__impl_zlib; @@ -64,7 +64,7 @@ int sqsh__extractor_init( struct SqshExtractor *extractor, struct SqshBuffer *buffer, int algorithm_id, size_t block_size) { - const struct SqshExtractorImpl *impl = extractor_by_id(algorithm_id); + const struct SqshExtractorImpl *impl = sqsh__extractor_impl_from_id(algorithm_id); if (impl == NULL) { return -SQSH_ERROR_COMPRESSION_UNSUPPORTED; }