File tree Expand file tree Collapse file tree 1 file changed +9
-11
lines changed
Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change 88
99#define PASSWORD_LENGTH 6
1010#define PROCESS_COUNT 4
11- #define TEST_READ_BYTES 16 // 只读取前16字节
1211
1312int try_password (const char * zip_path , const char * password ) {
1413 int err = 0 ;
1514 zip_t * za = zip_open (zip_path , 0 , & err );
1615 if (!za ) return 0 ;
17-
1816 if (zip_set_default_password (za , password ) < 0 ) {
1917 zip_close (za );
2018 return 0 ;
2119 }
22-
2320 zip_int64_t num_entries = zip_get_num_entries (za , 0 );
2421 int success = 0 ;
25-
2622 for (zip_uint64_t i = 0 ; i < num_entries ; i ++ ) {
2723 struct zip_stat st ;
2824 if (zip_stat_index (za , i , 0 , & st ) != 0 || st .size == 0 ) continue ;
29-
3025 zip_file_t * zf = zip_fopen_index (za , i , 0 );
3126 if (!zf ) continue ;
32-
33- char buffer [TEST_READ_BYTES ];
34- zip_int64_t total_read = zip_fread (zf , buffer , sizeof (buffer ));
27+ char * buffer = malloc (st .size );
28+ if (!buffer ) {
29+ zip_fclose (zf );
30+ continue ;
31+ }
32+ zip_int64_t total_read = zip_fread (zf , buffer , st .size );
3533 zip_fclose (zf );
36-
37- if (total_read > 0 ) { // 成功读到数据
34+ free (buffer );
35+ // 必须完整读到才算成功
36+ if (total_read == st .size ) {
3837 success = 1 ;
3938 break ;
4039 }
4140 }
42-
4341 zip_close (za );
4442 return success ;
4543}
You can’t perform that action at this time.
0 commit comments