You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Claude Warren Jr <cl...@xenei.com> on 2007/01/26 05:30:16 UTC

invalid LOC header (bad signature) when running in servlet only

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/xenei.net/coffeehouse/docs/calendar/Feb2007.sxw,
 i = 3,
 message = invalid LOC header (bad signature)
	java.util.zip.ZipFile$3.nextElement(ZipFile.java:429)
	java.util.zip.ZipFile$3.nextElement(ZipFile.java:415)
	java.util.jar.JarFile$1.nextElement(JarFile.java:217)
	java.util.jar.JarFile$1.nextElement(JarFile.java:216)
	org.xenei.cm.servlets.jarTest.list(jarTest.java:74)
	org.xenei.cm.servlets.jarTest.doGet(jarTest.java:84)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


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");
        try
        {
            DigestInputStream dis = new DigestInputStream( 
myURL.openStream(), md );
            byte[] buffer = new byte[1024];
           
            BufferedInputStream bis = new BufferedInputStream( dis );
            while (bis.read(buffer, 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: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: invalid LOC header (bad signature) when running in servlet only

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Claude Warren Jr [mailto:claude@xenei.com] 
> Subject: invalid LOC header (bad signature) when running in 
> servlet only
> 
>  message = invalid LOC header (bad signature)

This is an indication of a corrupted .zip file.  ZIP files can be read
either sequentially or via the table of contents at the end of the file;
the LOC header is only used when access is via the TOC.  The
java.util.zip classes use the TOC, while many other mechanisms use
sequential access and do not encounter the invalid LOC header.

One way this corruption can be introduced is by doing an FTP of the file
in ASCII mode using a Windows FTP client; this has the annoying habit of
converting LF characters into CR/LF sequences (or vice versa), which is
not something you want to do with a ZIP file.  You should be able to get
rid of the error by rebuilding the file.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org