For small files I can get the the zip_stat_t information, but if its a file 40Mb big I can't.
zip_stat_t info;
zip_stat_index(zipfile, 544, ZIP_FL_ENC_GUESS, &info);
printf("%s\n", info.name);
eg printing info.name is segfaulting for large files eg 40mb file. A 2Mb file will open with no problems. How can I get the size of info.name, for example since it it seems the info struct isn't being stored properly in RAM?
If I do printf(strlen(info.name)) it results in a segmentation fault.
What you experience is probably a failure of the info retrieval, so that the
namefield was invalid causing the segfault. The documentation doesn't mention size limits like those you experience.To avoid this behavior is recommended to check the return value of
zip_stat_index():Why did the index retrieval fail? Possibly the
indexprovided to the function (in your case544) is not present in the archive. In order to prevent this kind of "not found index" issues you can obtain the index of a given file usingzip_name_locate ()function:which returns either the index of
fnamewithinarchiveor-1if the file is not found.Alternatively you can just use
zip_stat()instead ofzip_stat_index()which saves one step as it allows to ask for a file name as a parameter: