Optionally ignore unsupported types instead of panicking
This commit is contained in:
parent
56d43f98ac
commit
d018d128a0
@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.8..3.22)
|
|||||||
|
|
||||||
project(minitar LANGUAGES C VERSION 1.3.0)
|
project(minitar LANGUAGES C VERSION 1.3.0)
|
||||||
|
|
||||||
|
option(MINITAR_IGNORE_UNSUPPORTED_TYPES "Skip past entries that have unsupported types instead of panicking" OFF)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
src/tar.c
|
src/tar.c
|
||||||
src/util.c
|
src/util.c
|
||||||
@ -9,6 +11,10 @@ set(SOURCES
|
|||||||
|
|
||||||
add_library(minitar STATIC ${SOURCES})
|
add_library(minitar STATIC ${SOURCES})
|
||||||
|
|
||||||
|
if(MINITAR_IGNORE_UNSUPPORTED_TYPES)
|
||||||
|
target_compile_definitions(minitar PRIVATE MINITAR_IGNORE_UNSUPPORTED_TYPES)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_include_directories(minitar PUBLIC ${CMAKE_CURRENT_LIST_DIR}) # for minitar.h
|
target_include_directories(minitar PUBLIC ${CMAKE_CURRENT_LIST_DIR}) # for minitar.h
|
||||||
|
|
||||||
set_target_properties(minitar PROPERTIES OUTPUT_NAME mtar)
|
set_target_properties(minitar PROPERTIES OUTPUT_NAME mtar)
|
||||||
|
@ -118,7 +118,7 @@ This enum lists all supported file types:
|
|||||||
|
|
||||||
`MTAR_DIRECTORY`: Directories
|
`MTAR_DIRECTORY`: Directories
|
||||||
|
|
||||||
Other file types supported in tar archives, such as block/character devices, FIFOs, or symlinks, are not supported and minitar will throw an error when encountering one of them.
|
Other file types supported in tar archives, such as block/character devices, FIFOs, or symlinks, are not supported and minitar will throw an error when encountering one of them. This behavior can be controlled by passing `-DMINITAR_IGNORE_UNSUPPORTED_TYPES=ON` to CMake when configuring, which will make minitar silently ignore such entries instead of panicking.
|
||||||
|
|
||||||
### minitar_entry_metadata
|
### minitar_entry_metadata
|
||||||
`struct minitar_entry_metadata`
|
`struct minitar_entry_metadata`
|
||||||
|
@ -168,9 +168,13 @@ void minitar_parse_metadata_from_tar_header(const struct tar_header* hdr, struct
|
|||||||
|
|
||||||
int minitar_validate_header(const struct tar_header* hdr)
|
int minitar_validate_header(const struct tar_header* hdr)
|
||||||
{
|
{
|
||||||
|
#ifdef MINITAR_IGNORE_UNSUPPORTED_TYPES
|
||||||
|
if (hdr->typeflag != '\0' && hdr->typeflag != '0' && hdr->typeflag != '5') return 0;
|
||||||
|
#else
|
||||||
if (hdr->typeflag != '\0' && hdr->typeflag != '0' && hdr->typeflag != '1' && hdr->typeflag != '2' &&
|
if (hdr->typeflag != '\0' && hdr->typeflag != '0' && hdr->typeflag != '1' && hdr->typeflag != '2' &&
|
||||||
hdr->typeflag != '3' && hdr->typeflag != '4' && hdr->typeflag != '5' && hdr->typeflag != '6')
|
hdr->typeflag != '3' && hdr->typeflag != '4' && hdr->typeflag != '5' && hdr->typeflag != '6')
|
||||||
return 0;
|
return 0;
|
||||||
|
#endif
|
||||||
return !strncmp(hdr->magic, "ustar", 5);
|
return !strncmp(hdr->magic, "ustar", 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user