mirror of
				https://github.com/eledio-devices/thirdparty-miniz.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	Fix corrupt archive if uncompressed file smaller than 4 byte and file is added by mz_zip_writer_add_mem*
This commit is contained in:
		
							
								
								
									
										22
									
								
								miniz_zip.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								miniz_zip.c
									
									
									
									
									
								
							| @@ -3186,6 +3186,17 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n | |||||||
|     } |     } | ||||||
| #endif /* #ifndef MINIZ_NO_TIME */ | #endif /* #ifndef MINIZ_NO_TIME */ | ||||||
|  |  | ||||||
|  | 	if (!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) | ||||||
|  | 	{ | ||||||
|  | 		uncomp_crc32 = (mz_uint32)mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, buf_size); | ||||||
|  | 		uncomp_size = buf_size; | ||||||
|  | 		if (uncomp_size <= 3) | ||||||
|  | 		{ | ||||||
|  | 			level = 0; | ||||||
|  | 			store_data_uncompressed = MZ_TRUE; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|     archive_name_size = strlen(pArchive_name); |     archive_name_size = strlen(pArchive_name); | ||||||
|     if (archive_name_size > MZ_UINT16_MAX) |     if (archive_name_size > MZ_UINT16_MAX) | ||||||
|         return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME); |         return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME); | ||||||
| @@ -3309,17 +3320,6 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n | |||||||
| 		cur_archive_file_ofs += user_extra_data_len; | 		cur_archive_file_ofs += user_extra_data_len; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|     if (!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) |  | ||||||
|     { |  | ||||||
|         uncomp_crc32 = (mz_uint32)mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, buf_size); |  | ||||||
|         uncomp_size = buf_size; |  | ||||||
|         if (uncomp_size <= 3) |  | ||||||
|         { |  | ||||||
|             level = 0; |  | ||||||
|             store_data_uncompressed = MZ_TRUE; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     if (store_data_uncompressed) |     if (store_data_uncompressed) | ||||||
|     { |     { | ||||||
|         if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pBuf, buf_size) != buf_size) |         if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pBuf, buf_size) != buf_size) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user