Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » BUG: plugins\zip
icon4.gif  BUG: plugins\zip [message #24490] Wed, 20 January 2010 11:46 Go to next message
kov_serg is currently offline  kov_serg
Messages: 37
Registered: August 2008
Location: Russia
Member
I found simple bug in zip plugin for Upp. Please fix it.

Symptoms

Testing code:
void test_code() {
	FileStream strm("test.zip",FileStream::CREATE);
	Zip zip(strm);
	zip.WriteFile("information","file1.txt");
	zip.WriteFile("text 1","file2.txt");
}


If we check archive we'll see damaged zip file Sad

How to fix it:

In file uppsrc\plugin\zip\Zip.cpp
void Zip::WriteFile(const void *ptr, int size, const char *path, Gate2<int, int> progress, Time tm)
{
	File& f = file.Add();
	f.path = UnixPath(path);
	StringStream ss;
	MemReadStream ms(ptr, size);
	dword crc;
	ZCompress(ss, ms, size, progress, true, &crc);
	String data = ss.GetResult();
	const void *r = ~data;
	int   csize = data.GetLength();
	zip->Put32le(0x04034b50);
	zip->Put16le(20);
	zip->Put16le(0);
	if(data.GetLength() >= size) {
		r = ptr;
		csize = size;
		zip->Put16le(f.method = 0);
	}
	else
		zip->Put16le(f.method = 8);
	zip->Put32le(f.time = (tm.day << 16) | (tm.month << 21) | ((tm.year - 1980) << 25) |
	                      (tm.hour << 11) | (tm.minute << 5) | (tm.second >> 1));
	zip->Put32le(f.crc = crc);
	zip->Put32le(f.csize = csize);
	zip->Put32le(f.usize = size);
	zip->Put16le(strlen(f.path));
	zip->Put16le(0);
	zip->Put(f.path);
	zip->Put(r, csize);
	//done += 5 * 2 + 5 * 4 + data.GetCount() + f.path.GetCount(); // -patch
	done += 5 * 2 + 5 * 4 + csize + f.path.GetCount(); // +patch
}
...
void Zip::Finish()
{
	if(!zip)
		return;
	dword off = done;
	dword rof = 0;// +patch
	for(int i = 0; i < file.GetCount(); i++) {
		File& f = file[i];
		zip->Put32le(0x02014b50);
		zip->Put16le(20);
		zip->Put16le(20);
		zip->Put16le(0);  // general purpose bit flag
		zip->Put16le(f.method);
		zip->Put32le(f.time);
		zip->Put32le(f.crc);
		zip->Put32le(f.csize);
		zip->Put32le(f.usize);
		zip->Put16le(f.path.GetCount());
		zip->Put16le(0); // extra field length              2 bytes
		zip->Put16le(0); // file comment length             2 bytes
		zip->Put16le(0); // disk number start               2 bytes
		zip->Put16le(0); // internal file attributes        2 bytes
		zip->Put32le(0); // external file attributes        4 bytes
		//zip->Put32le(0); // relative offset of local header 4 bytes // -patch
		zip->Put32le(rof); // relative offset of local header 4 bytes // +patch
		rof+=5 * 2 + 5 * 4 + f.csize + f.path.GetCount();// +patch
		zip->Put(f.path);
		done += 7 * 4 + 9 * 2 + f.path.GetCount();
	}
	zip->Put32le(0x06054b50);
	zip->Put16le(0);  // number of this disk
	zip->Put16le(0);  // number of the disk with the start of the central directory
	zip->Put16le(file.GetCount()); // total number of entries in the central directory on this disk
	zip->Put16le(file.GetCount()); // total number of entries in the central directory
	zip->Put32le(done - off); // size of the central directory
	zip->Put32le(off); //offset of start of central directory with respect to the starting disk number
	zip->Put16le(0);
	zip = NULL;
}
Re: BUG: plugins\zip [message #24491 is a reply to message #24490] Wed, 20 January 2010 13:44 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Oh! I did not know we have .zip support Embarassed

Best regards
IƱaki
Re: BUG: plugins\zip [message #24517 is a reply to message #24491] Thu, 21 January 2010 22:57 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Thank you, patch applied.

Mirek
Previous Topic: Polymorphic XML
Next Topic: Wrong icon16x16.png file
Goto Forum:
  


Current Time: Fri Mar 29 11:43:51 CET 2024

Total time taken to generate the page: 0.01114 seconds