/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 6334171
* @summary Test that zip file's data descriptor is written correctly.
*/
/**
* Bug 6252735 ZipEntry contains wasteful "temporary storage" fields introduced
* a regression. The value of the general purpose flag bit in a LOC header is
* written incorrectly, because it is computed on stale data.
* <p>
* With the bug present, zipbytes2 is written incorrectly: when the LOC
* header is written, (flag(e) & 8) == 8. This is correct: the data will be
* compressed, so we don't have data length, etc. yet; that should be written
* in the DataDescriptor after the data itself is written. However, when the
* ZipOutputStream that wraps zipbytes2 is closed, the data length _is_
* available, therefore (flag(e) & 8) = 0), therefore the DataDescriptor is
* not written. This is why, with the bug, zipbytes1.length == sizeof(ext
* header) + zipbytes2.length.
* <p>
* The result is an invalid LOC header in zipbytes2. So when we again use
* copyZip, we attempt to read a data length not from the LOC header but from
* the non-existent EXT header, and at that position in the file is some
* arbitrary and incorrect value.
*/
public class DataDescriptor {
// When the bug is present, it shows up here. The second call to
// copyZip will throw an exception while reading data.
}
}
}
// Create zip output in byte array zipbytes
zos.putNextEntry(e);
// Make a ZipInputStream around zipbytes, and use
// copyZip to get a new byte array.
new ZipInputStream(
new ByteArrayInputStream(zipbytes1));
// When the bug is present, pre- and post-copy lengths are different!
// Now use copyZip again on the bytes resulting from the previous
// copy. When the bug is present, copyZip will get an exception this
// time.
}
//--------------------- Infrastructure ---------------------------
else fail(x + " not equal to " + y);}
}