88
99typedef struct {
1010 char * filename ;
11+ char * symlink ;
1112 uint8_t * data ;
1213 size_t data_size ;
1314} FileData ;
@@ -57,13 +58,27 @@ ExtractedArchive* extract_archive(uint8_t* inputData, size_t inputSize ) {
5758 archive_read_support_format_all (archive );
5859
5960 if (archive_read_open_memory (archive , inputData , inputSize ) != ARCHIVE_OK ) {
60- return error_handler (result ,archive_error_string (archive ), archive );
61+ return error_handler (result ,archive_error_string (archive ), archive );
6162 }
6263 files = malloc (sizeof (FileData ) * files_struct_length );
6364
6465 while (archive_read_next_header (archive , & entry ) == ARCHIVE_OK ) {
6566 const char * filename = archive_entry_pathname (entry );
6667 size_t entrySize = archive_entry_size (entry );
68+
69+ if (archive_entry_filetype (entry ) == AE_IFLNK ) {
70+ // It's a symbolic link
71+ const char * target = archive_entry_symlink (entry );
72+
73+ files [files_count ].filename = strdup (filename );
74+ files [files_count ].symlink = strdup (target );
75+
76+ files_count ++ ;
77+
78+ continue ;
79+ }
80+
81+
6782 if (files_count + 1 > files_struct_length ) {
6883 files_struct_length *= 2 ; // double the length
6984 FileData * oldfiles = files ;
@@ -73,9 +88,10 @@ ExtractedArchive* extract_archive(uint8_t* inputData, size_t inputSize ) {
7388 result -> files = oldfiles ; // otherwise memory is lost, alternatively also everything can be freed.
7489 error_message = "Memory allocation error for file data." ;
7590 return error_handler (result , error_message , archive );
76- }
91+ }
7792 }
7893 files [files_count ].filename = strdup (filename );
94+ files [files_count ].symlink = strdup ("" );
7995 files [files_count ].data = malloc (entrySize );
8096 files [files_count ].data_size = entrySize ;
8197
@@ -150,7 +166,7 @@ ExtractedArchive* decompression(uint8_t* inputData, size_t inputSize) {
150166
151167 const size_t buffsize = 64 * 1024 ;
152168 char buff [buffsize ];
153- size_t total_size = 0 ;
169+ size_t total_size = 0 ;
154170 const char * error_message ;
155171
156172 FileData * files = malloc (sizeof (FileData ) * (files_count + 1 ));
@@ -159,7 +175,7 @@ ExtractedArchive* decompression(uint8_t* inputData, size_t inputSize) {
159175 printf ("Failed to allocate memory for files array\n" );
160176 return NULL ;
161177 }
162-
178+
163179 ExtractedArchive * result = (ExtractedArchive * )malloc (sizeof (ExtractedArchive ));
164180 if (!result ) {
165181 free (files );
@@ -194,6 +210,7 @@ ExtractedArchive* decompression(uint8_t* inputData, size_t inputSize) {
194210 if (!filename ) filename = "decompression" ;
195211
196212 files [files_count ].filename = strdup (filename );
213+ files [files_count ].symlink = strdup ("" );
197214 files [files_count ].data = NULL ;
198215 files [files_count ].data_size = 0 ;
199216
@@ -259,4 +276,4 @@ void free_extracted_archive(ExtractedArchive* archive) {
259276 }
260277 free (archive -> files );
261278 free (archive );
262- }
279+ }
0 commit comments