Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I followed an article on here on how to unzip jar files using ICSharpCode.SharpZipLib, needing only a small portion of the code that being;

VB
Dim fz As New FastZip()
     fz.ExtractZip(jarpath, savefolderpath, "")


However the particular jar file I'm trying to unzip is causing a problem, I get the error;

VB
ArguementOutOfRangeException was unhandled
Specified argument was out of the range of valid values.
Parameter name: length

When trying to extract it. Since getting this error I've read the MSDN articles on it (barely understanding them) and made some test jar files (they extracted fine).

I looked into the extracted folder to see what might be causing the error, it turns out there's a file named 'null' that is linked to several other .class files causing the extraction to throw this error.

The null file shows 0kb file size in both extracted and zipped form when using WinRAR.

I was wondering if there was anyway to get around this error?

Please keep in mind I'm still new to VB.
Posted
Updated 14-Mar-12 1:41am
v3

That looks like a possible bug in the library. You probably need to download the source and see if you can find the point of failure and add some code to work round it.
 
Share this answer
 
I have no understanding of C#, which is what the lib is wrote in.

I'll download the source anyway and see what I can understand of it, from what I've been told there are similarities between the two languages. Any idea what I might need to look for in the source code?


Edit:

Having downloaded the source files I opened them in VS 2010 and started looking through the files one at a time, I came across this bit of code but don't fully understand if it's causing my problem. I see the exception I'm getting, so I'm assuming this is the culprit.

C#
/// <summary>
		/// Add a new entry to extra data
		/// </summary>
		/// <param name="headerID">The ID for this entry.</param>
		/// <param name="fieldData">The data to add.</param>
		/// <remarks>If the ID already exists its contents are replaced.</remarks>
		public void AddEntry(int headerID, byte[] fieldData)
		{
			if ( (headerID > ushort.MaxValue) || (headerID < 0)) {
				throw new ArgumentOutOfRangeException("headerID");
			}

			int addLength = (fieldData == null) ? 0 : fieldData.Length;

			if ( addLength > ushort.MaxValue ) {
#if NETCF_1_0
				throw new ArgumentOutOfRangeException("fieldData");
#else
				throw new ArgumentOutOfRangeException("fieldData", "exceeds maximum length");
#endif
			}

			// Test for new length before adjusting data.
			int newLength = _data.Length + addLength + 4;

			if ( Find(headerID) )
			{
				newLength -= (ValueLength + 4);
			}

			if ( newLength > ushort.MaxValue ) {
				throw new ZipException("Data exceeds maximum length");
			}
			
			Delete(headerID);

			byte[] newData = new byte[newLength];
			_data.CopyTo(newData, 0);
			int index = _data.Length;
			_data = newData;
			SetShort(ref index, headerID);
			SetShort(ref index, addLength);
			if ( fieldData != null ) {
				fieldData.CopyTo(newData, index);
			}
		}
 
Share this answer
 
v2
Comments
Richard MacCutchan 14-Mar-12 9:17am    
This does not look like the correct place. Your original message suggested that the exception occurs when the length field is zero during an unzip operation; I suspect it may look like throw new ArgumentOutOfRangeException("length");
I did a more specific search based on what Richard suggested and got 2 results that are verbatim with his suggestion.

Search 1 is in a file titled
C#
InflaterInputStream.cs


C#
/// <summary>
		/// Read clear text data from the input stream.
		/// </summary>
		/// <param name="outBuffer">The buffer to add data to.</param>
		/// <param name="offset">The offset to start adding data at.</param>
		/// <param name="length">The number of bytes to read.</param>
		/// <returns>Returns the number of bytes actually read.</returns>
		public int ReadClearTextBuffer(byte[] outBuffer, int offset, int length)
		{
			if ( length < 0 ) {
				throw new ArgumentOutOfRangeException("length");
			}
			
			int currentOffset = offset;
			int currentLength = length;
			
			while ( currentLength > 0 ) {
				if ( available <= 0 ) {
					Fill();
					if (available <= 0) {
						return 0;
					}
				}
				
				int toCopy = Math.Min(currentLength, available);
				Array.Copy(clearText, clearTextLength - (int)available, outBuffer, currentOffset, toCopy);
				currentOffset += toCopy;
				currentLength -= toCopy;
				available -= toCopy;
			}
			return length;
		}




Search 2 is in a file called
C#
StreamManipulator.cs
(for the sake of not posting a ton of code I'll only post the exception);

C#
/// <exception cref="ArgumentOutOfRangeException">
		/// Length is less than zero
		/// </exception>
public int CopyBytes(byte[] output, int offset, int length)
		{
			if (length < 0) {
				throw new ArgumentOutOfRangeException("length");
			}


More descriptive notes for search 2;

C#
/// <summary>
		/// Copies bytes from input buffer to output buffer starting
		/// at output[offset].  You have to make sure, that the buffer is
		/// byte aligned.  If not enough bytes are available, copies fewer
		/// bytes.
		/// </summary>




With the problem found, how can I fix it without breaking the lib? I really don't know anything about coding with C#. Is it as simple as removing the 'if' statement or changing the value?


Edit: I simply deleted the 'if' statements that throws the Exception and it's working perfectly.
 
Share this answer
 
v2
the giving code working properly on my end

pls check any installation check of java or .Net
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900