Open liufengwenyu opened 1 year ago
Which version of zip file are you using? I was unable to reproduce this issue. When I added a file to an existing zip file, I got the right output. Below are some screenshots:
And I see in your screenshot that there are two entries in the zip file with the same filename META-INF/CERT.RSA. This shouldn't have been the case if the file was added by zip4j. Zip4j replaces a file if an entry in zip exists already with the same name that you are adding.
I'm using version 2.11.5 and I'm sorry I can't upload my sample because it's over 25M. The difference between it and other normal zips is that it has a data descriptor area, as shown in the image below When the file is added, the last bit of the original zip file is preserved as if the buffer was not truncated.
Another strange thing is that when I use 7zip to arbitrarily delete a file from the original zip, and then use zip4j to add the file, it behaves normally.
A zip file has a data descriptor, and when a new file is added, there will be additional data at the end of the zip file.
struct ZIPDIRENTRY dirEntry[341]
is the new filestruct ZIPENDLOCATOR endLocator[0]
is theEnd of central directory record
of the new zipstruct ZIPDIRENTRY dirEntry[342]
is the is the last file of the old zipstruct ZIPENDLOCATOR endLocator[1]
is theEnd of central directory record
of the old zipstruct ZIPDIRENTRY dirEntry[342]
andstruct ZIPENDLOCATOR endLocator[1]
are redundantBelow is my code