ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r677514 - in /ant/core/trunk: ./ src/main/org/apache/tools/bzip2/ src/tests/junit/org/apache/tools/bzip2/
Date Thu, 17 Jul 2008 06:58:40 GMT
Author: bodewig
Date: Wed Jul 16 23:58:39 2008
New Revision: 677514

URL: http://svn.apache.org/viewvc?rev=677514&view=rev
Log:
More sanity in CBZip2*Stream if the streams are empty.  PR 32200. Submitted by Kevin Jackson.

Added:
    ant/core/trunk/src/tests/junit/org/apache/tools/bzip2/
    ant/core/trunk/src/tests/junit/org/apache/tools/bzip2/CBZip2StreamTest.java   (with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/bzip2/CBZip2InputStream.java
    ant/core/trunk/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=677514&r1=677513&r2=677514&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Wed Jul 16 23:58:39 2008
@@ -54,6 +54,10 @@
    however the configuration-from-String behavior remains equivalent, rendering
    a FileResource.
 
+ * CBZip2InputStream will now throw an IOException if
+   passed in a null or empty InputStream to read from.
+   Bugzilla Report 32200
+
 Fixed bugs:
 -----------
 
@@ -112,6 +116,10 @@
  * <scp> creates remoteToDir if it doesn't exist.
    Bugzilla Report 42781
 
+ * CBZip2OutputStream threw an exception if it was closed prior to
+   writing anything.
+   Bugzilla Report 32200
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/bzip2/CBZip2InputStream.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/bzip2/CBZip2InputStream.java?rev=677514&r1=677513&r2=677514&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/bzip2/CBZip2InputStream.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/bzip2/CBZip2InputStream.java Wed Jul 16 23:58:39
2008
@@ -23,8 +23,9 @@
  */
 package org.apache.tools.bzip2;
 
-import java.io.InputStream;
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 
 /**
  * An input stream that decompresses from the BZip2 format (without the file
@@ -223,6 +224,12 @@
     }
 
     private void init() throws IOException {
+        if (null == in) {
+            throw new IOException("No InputStream");
+        }
+        if (in.available() == 0) {
+            throw new IOException("Empty InputStream");
+        }
         int magic2 = this.in.read();
         if (magic2 != 'h') {
             throw new IOException("Stream is not BZip2 formatted: expected 'h'"

Modified: ant/core/trunk/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java?rev=677514&r1=677513&r2=677514&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java Wed Jul 16 23:58:39
2008
@@ -503,7 +503,7 @@
                     code[i] = vec;
                     vec++;
                 }
-            };
+            }
             vec <<= 1;
         }
     }
@@ -703,7 +703,7 @@
                         bc = cost[t];
                         bt = t;
                     }
-                };
+                }
                 totc += bc;
                 fave[bt]++;
                 selector[nSelectors] = (char) bt;
@@ -1047,7 +1047,7 @@
                         ltLo++;
                         unLo++;
                         continue;
-                    };
+                    }
                     if (n >  0) {
                         break;
                     }
@@ -1066,7 +1066,7 @@
                         gtHi--;
                         unHi--;
                         continue;
-                    };
+                    }
                     if (n <  0) {
                         break;
                     }
@@ -1131,6 +1131,15 @@
         */
 
         //   if (verbosity >= 4) fprintf ( stderr, "   sort initialise ...\n" );
+        
+        // set last to zero in case it's never been set before
+        // see bug#32200, initBlock is the real culprit 
+        // setting last to -1, but not sure if this -1 is important
+        // in normal scheme
+        if (last < 0) {
+            last = 0;
+        }
+        
         for (i = 0; i < NUM_OVERSHOOT_BYTES; i++) {
             block[last + i + 2] = block[(i % (last + 1)) + 1];
         }
@@ -1360,7 +1369,7 @@
                 origPtr = i;
                 break;
             }
-        };
+        }
 
         if (origPtr == -1) {
             panic();
@@ -1478,11 +1487,11 @@
             if (i1 > last) {
                 i1 -= last;
                 i1--;
-            };
+            }
             if (i2 > last) {
                 i2 -= last;
                 i2--;
-            };
+            }
 
             k -= 4;
             workDone++;
@@ -1565,7 +1574,7 @@
                 tmp2 = tmp;
                 tmp = yy[j];
                 yy[j] = tmp2;
-            };
+            }
             yy[0] = tmp;
 
             if (j == 0) {
@@ -1585,12 +1594,12 @@
                             wr++;
                             mtfFreq[RUNB]++;
                             break;
-                        };
+                        }
                         if (zPend < 2) {
                             break;
                         }
                         zPend = (zPend - 2) / 2;
-                    };
+                    }
                     zPend = 0;
                 }
                 szptr[wr] = (short) (j + 1);
@@ -1627,6 +1636,4 @@
 
         nMTF = wr;
     }
-}
-
-
+}
\ No newline at end of file

Added: ant/core/trunk/src/tests/junit/org/apache/tools/bzip2/CBZip2StreamTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/bzip2/CBZip2StreamTest.java?rev=677514&view=auto
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/bzip2/CBZip2StreamTest.java (added)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/bzip2/CBZip2StreamTest.java Wed Jul 16
23:58:39 2008
@@ -0,0 +1,42 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.tools.bzip2;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+public class CBZip2StreamTest extends TestCase {
+
+    public void testNullPointer() throws IOException {
+        try {
+            CBZip2InputStream cb = new CBZip2InputStream(new ByteArrayInputStream(new byte[0]));
+            fail("expected an exception");
+        } catch (IOException e) {
+            // expected
+        }
+    }
+    
+    public void testDivisionByZero() throws IOException {
+        CBZip2OutputStream cb = new CBZip2OutputStream(new ByteArrayOutputStream());
+        cb.close();
+        // expected no exception
+    }
+}

Propchange: ant/core/trunk/src/tests/junit/org/apache/tools/bzip2/CBZip2StreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message