tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claude Warren Jr <>
Subject invalid LOC header (bad signature) when running in servlet only
Date Fri, 26 Jan 2007 04:30:16 GMT
I have an web application that takes OpenOffice 1.1 files and converts 
them to web pages.  I have a single sxw file that causes an exception 
but only when run in the servlet.

When running in the servlet I get:

java.lang.InternalError: jzentry == 0,
 jzfile = 138986592,
 total = 6,
 name = /content/,
 i = 3,
 message = invalid LOC header (bad signature)$3.nextElement($3.nextElement(

I have isolated the code in a small servlet:

public class jarTest extends HttpServlet  {

    public jarTest()
    private void digest(HttpServletRequest req, HttpServletResponse 
resp) throws IOException, NoSuchAlgorithmException
        String urlString = req.getParameter("digest");
        PrintWriter writer = resp.getWriter();
        writer.println( "=====> "+urlString );
        URL myURL = new URL( "file:"+urlString  );
        MessageDigest md = MessageDigest.getInstance("MD5");
            DigestInputStream dis = new DigestInputStream( 
myURL.openStream(), md );
            byte[] buffer = new byte[1024];
            BufferedInputStream bis = new BufferedInputStream( dis );
            while (, 0, 1024 ) > -1)
                // do nothing
            byte[] digest = dis.getMessageDigest().digest();
            writer.println( myURL.toString()+" digest is: "+Hex.encode( 
digest ) );
        catch (Exception e)
            writer.println( "ERROR" );
            e.printStackTrace( writer );
    private void list(HttpServletRequest req, HttpServletResponse resp) 
throws IOException
        String urlString = req.getParameter("url");
        PrintWriter writer = resp.getWriter();
        writer.println( "=====> "+urlString );
        URL myURL = new URL( "jar:file:"+urlString+"!/"  );
        writer.println( "Opening URL: "+myURL );
        JarFile jarFile;
        // open the jarfile.
        JarURLConnection conn = (JarURLConnection) myURL.openConnection();
        jarFile = conn.getJarFile();
        Enumeration entries = jarFile.entries();
        JarEntry entry;
        while (entries.hasMoreElements() )
            entry = (JarEntry)entries.nextElement();  // <----------- 
Error occurs here
            writer.println( "processing: "+entry.getName() );
        writer.println( "<=====" );

    protected void doGet(HttpServletRequest req, HttpServletResponse 
resp) throws ServletException, IOException
        if (req.getParameter("url") != null)
            list( req, resp );
        if (req.getParameter("digest") != null)
            try {
                digest( req, resp );
            } catch (NoSuchAlgorithmException e) {
                // TODO Auto-generated catch block
                throw new ServletException( e.getMessage(), e );

This servlet will either list the the contents of the jar (sxw) file 
with the url= argument or provide the MD5 digest for the contents of the 
file if called with the digest= argument.

I have placed the same code in a stand alone app and it will read the 
file without problem.  The MD5 digest of the bytes is the same both in 
the servlet and in the stand alone.

This fails only in the servlet and, thus far, only with the one file.

All other tools that can read zip files that I have access to are able 
to read the file, furthermore OpenOffice 1.1 can read it as well.  I 
have not tried to rewrite it as I want to make sure that I understand 
why the servlet fails in this case so that I can attempt to account for 
it in future cases.

Any help with this would be appreciated.  I will gladly provide the 
servlet, stand alone, and sxw file for anyone that is interested in 
looking at this problem.

Many Thanks,
Claude Warren

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message