Crashed when reading Java zipped or jarred files

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
dude3d
Posts: 25
Joined: Thu Sep 06, 2007 3:45 am

Crashed when reading Java zipped or jarred files

Post by dude3d »

Hi all,

My project requires to use Irrlicht read Java zipped or jarred files. I tried to add them to the file system cache by using

Code: Select all

device->getFileSystem()->addZipFileArchive(...)
then read them with

Code: Select all

device->getFileSystem()->createAndOpenFile(...)
Each time Irrlicht crashed. But the wired thing is that Irrlicht works fine if I use it to read a WinZip created file. Here is the test case code:

Code: Select all

#include <irrlicht.h>
#include <iostream>

using namespace irr;

#pragma comment(lib, "Irrlicht.lib")

int main()
{
	IrrlichtDevice *device =
		createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(640, 480));

	if (device == 0)
		return 1; // could not create selected driver.

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();

	device->getFileSystem()->addZipFileArchive("./derbyclient.jar", true, false);

	irr::io::IReadFile* indexFile = device->getFileSystem()->createAndOpenFile("META-INF/eclipse.inf");
	char* indexXml = new char[indexFile->getSize() + 1];
	irr::s32 fileSize = indexFile->read(indexXml, indexFile->getSize());
	indexXml[fileSize] = '\0';
	std::cout << indexXml << std::endl;
	delete [] indexXml;
	device->drop();
	indexFile->drop();
	return 0;
}
In theory, a Jar file is as same as a Zip file. and In Java a Zip is created by the same algorithm as a Jar.

In the above code, indexFile is always returned 0.

The root cause of this problem is that in "CZipReader.cpp", the "entry.header.GeneralBitFlag" for a Java zipped or jarred file is 8 so Irrlicht tries to get CRC32, CompressedSize and UncompressedSize from the Zip or the Jar, but they are not set by Java. But when I read a WinZip created file, "entry.header.GeneralBitFlag" is 0.

But WinZip can open Java zipped or jarred files without any problem.

Does anybody know a solution about this problem?

Thanks
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

I dont think you should be using create and open file. That is trying to create a new file inside the jar file?

Also check your paths in the adding of the archive, whther they hold or not..
dude3d
Posts: 25
Joined: Thu Sep 06, 2007 3:45 am

Post by dude3d »

Thank you for the reply mate! But the document in Irrlicht does not agree with what you said:

Code: Select all

	//! Opens a file for read access.
	/** \param filename: Name of file to open.
	\return Returns a pointer to the created file interface.
	The returned pointer should be dropped when no longer needed.
	See IReferenceCounted::drop() for more information. */
	virtual IReadFile* createAndOpenFile(const c8* filename) = 0;
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

I shouldnt read and post replies after stumbling out of bed :)

I can see how the bit flag in your header is causing trouble. Why dont you grab a hex editor and hax that 8 into a 0? if the jar is still valid for java, and irrlicht, why not just mod the file itself?
dude3d
Posts: 25
Joined: Thu Sep 06, 2007 3:45 am

Post by dude3d »

Thank you FuzzYspo0N. But I suspect that won't work because I tried to change the bit flag to 0 through vc++ debugger and the problem still existed. I think Java somehow messed up the header of the zip file.

To bypass this problem, I've changed to call OS zip commands at the Java side to create the zip. Irrlicht is happy with OS generated zip. This is a hack though.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

There's a whole host of different zip file headers, perhaps it's being recognised as the wrong type.
Reading the source to gzip or 7-zip may help figure out where we're going wrong, if you work it out, please submit a patch :)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
dude3d
Posts: 25
Joined: Thu Sep 06, 2007 3:45 am

Post by dude3d »

Will do it when I have some bandwidth.
Post Reply