Program: 44910
Project: 44910
Buggy source:
/** 
 * Reads the central directory of the given archive and populates the internal tables with ZipEntry instances. <p>The ZipEntrys will know all data that can be obtained from the central directory alone, but not the data that requires the local file header or additional data to be read.</p>
 * @throws IOException if an I/O error occurred
 * @throws ZipException if this file is not a valid Zip file
 */
private void parseCentralDirectory() throws IOException, ZipException {
  positionAtCentralDirectory();
  byte[] cfh=new byte[CFH_LEN];
  byte[] signatureBytes=new byte[4];
  rais.readFully(signatureBytes);
  long sig=ZipLong.getValue(signatureBytes);
  final long cfhSig=ZipLong.getValue(CFH_SIG);
  boolean defaultEncodingSet=defaultEncoding != null;
  ByteArrayOutputStream encodingAccumulator=defaultEncodingSet ? null : new ByteArrayOutputStream();
  while (sig == cfhSig) {
    ZipEntryInfo entryInfo=new ZipEntryInfo();
    entryInfo.centralHeaderOffset=rais.getOffset() - 4;
    rais.readFully(cfh);
    ZipEntry ze=new ZipEntry();
    int versionMadeBy=ZipShort.getValue(cfh,0);
    ze.setPlatform((versionMadeBy >> 8) & 0x0F);
    int gp=ZipShort.getValue(cfh,4);
    boolean isUTF8=(gp & 0x800) != 0;
    if (isUTF8) {
      entryInfo.encoding=UTF_8;
      if (Debug.ON)       Debug.trace("String_Node_Str");
    }
 else     if (defaultEncodingSet) {
      entryInfo.encoding=defaultEncoding;
      if (Debug.ON)       Debug.trace("String_Node_Str" + defaultEncoding);
    }
 else {
    }
    entryInfo.hasDataDescriptor=(gp & 8) != 0;
    int method=ZipShort.getValue(cfh,6);
    if (method != DEFLATED && method != STORED)     throw new ZipException("String_Node_Str");
    ze.setMethod(method);
    ze.setDosTime(ZipLong.getValue(cfh,8));
    ze.setCrc(ZipLong.getValue(cfh,12));
    ze.setCompressedSize(ZipLong.getValue(cfh,16));
    ze.setSize(ZipLong.getValue(cfh,20));
    int fileNameLen=ZipShort.getValue(cfh,24);
    int extraLen=ZipShort.getValue(cfh,26);
    int commentLen=ZipShort.getValue(cfh,28);
    ze.setInternalAttributes(ZipShort.getValue(cfh,32));
    ze.setExternalAttributes(ZipLong.getValue(cfh,34));
    byte[] filename=new byte[fileNameLen];
    rais.readFully(filename);
    if (entryInfo.encoding != null) {
      ze.setName(getString(filename,entryInfo.encoding));
    }
 else {
      entryInfo.filename=filename;
      feedEncodingAccumulator(encodingAccumulator,filename);
    }
    entryInfo.headerOffset=ZipLong.getValue(cfh,38);
    byte extra[]=new byte[extraLen];
    rais.readFully(extra);
    ze.setExtra(extra);
    byte[] comment=new byte[commentLen];
    rais.readFully(comment);
    if (entryInfo.encoding != null) {
      ze.setComment(getString(comment,entryInfo.encoding));
    }
 else {
      entryInfo.comment=comment;
      feedEncodingAccumulator(encodingAccumulator,comment);
    }
    entryInfo.centralHeaderLen=46 + fileNameLen + extraLen+ commentLen;
    ze.setEntryInfo(entryInfo);
    entries.add(ze);
    nameMap.put(ze.getName(),ze);
    rais.readFully(signatureBytes);
    sig=ZipLong.getValue(signatureBytes);
  }
  if (encodingAccumulator != null && encodingAccumulator.size() > 0) {
    int nbEntries=entries.size();
    String guessedEncoding=EncodingDetector.detectEncoding(encodingAccumulator.toByteArray());
    if (Debug.ON)     Debug.trace("String_Node_Str" + guessedEncoding);
    ZipEntry entry;
    ZipEntryInfo entryInfo;
    for (int i=0; i < nbEntries; i++) {
      entry=(ZipEntry)entries.elementAt(i);
      entryInfo=entry.getEntryInfo();
      if (entryInfo.encoding != null)       continue;
      entryInfo.encoding=guessedEncoding;
      entry.setName(getString(entryInfo.filename,guessedEncoding));
      entryInfo.filename=null;
      entry.setComment(getString(entryInfo.comment,guessedEncoding));
      entryInfo.comment=null;
    }
  }
}

Fixed version (ground truth):
/** 
 * Reads the central directory of the given archive and populates the internal tables with ZipEntry instances. <p>The ZipEntrys will know all data that can be obtained from the central directory alone, but not the data that requires the local file header or additional data to be read.</p>
 * @throws IOException if an I/O error occurred
 * @throws ZipException if this file is not a valid Zip file
 */
private void parseCentralDirectory() throws IOException, ZipException {
  positionAtCentralDirectory();
  byte[] cfh=new byte[CFH_LEN];
  byte[] signatureBytes=new byte[4];
  rais.readFully(signatureBytes);
  long sig=ZipLong.getValue(signatureBytes);
  final long cfhSig=ZipLong.getValue(CFH_SIG);
  boolean defaultEncodingSet=defaultEncoding != null;
  ByteArrayOutputStream encodingAccumulator=defaultEncodingSet ? null : new ByteArrayOutputStream();
  while (sig == cfhSig) {
    ZipEntryInfo entryInfo=new ZipEntryInfo();
    entryInfo.centralHeaderOffset=rais.getOffset() - 4;
    rais.readFully(cfh);
    ZipEntry ze=new ZipEntry();
    int versionMadeBy=ZipShort.getValue(cfh,0);
    ze.setPlatform((versionMadeBy >> 8) & 0x0F);
    int gp=ZipShort.getValue(cfh,4);
    boolean isUTF8=(gp & 0x800) != 0;
    if (isUTF8) {
      entryInfo.encoding=UTF_8;
      if (Debug.ON)       Debug.trace("String_Node_Str");
    }
 else     if (defaultEncodingSet) {
      entryInfo.encoding=defaultEncoding;
      if (Debug.ON)       Debug.trace("String_Node_Str" + defaultEncoding);
    }
 else {
    }
    entryInfo.hasDataDescriptor=(gp & 8) != 0;
    int method=ZipShort.getValue(cfh,6);
    if (method != DEFLATED && method != STORED)     throw new ZipException("String_Node_Str");
    ze.setMethod(method);
    ze.setDosTime(ZipLong.getValue(cfh,8));
    ze.setCrc(ZipLong.getValue(cfh,12));
    ze.setCompressedSize(ZipLong.getValue(cfh,16));
    ze.setSize(ZipLong.getValue(cfh,20));
    int fileNameLen=ZipShort.getValue(cfh,24);
    int extraLen=ZipShort.getValue(cfh,26);
    int commentLen=ZipShort.getValue(cfh,28);
    ze.setInternalAttributes(ZipShort.getValue(cfh,32));
    ze.setExternalAttributes(ZipLong.getValue(cfh,34));
    byte[] filename=new byte[fileNameLen];
    rais.readFully(filename);
    if (entryInfo.encoding != null) {
      setFilename(ze,getString(filename,entryInfo.encoding));
    }
 else {
      entryInfo.filename=filename;
      feedEncodingAccumulator(encodingAccumulator,filename);
    }
    entryInfo.headerOffset=ZipLong.getValue(cfh,38);
    byte extra[]=new byte[extraLen];
    rais.readFully(extra);
    ze.setExtra(extra);
    byte[] comment=new byte[commentLen];
    rais.readFully(comment);
    if (entryInfo.encoding != null) {
      ze.setComment(getString(comment,entryInfo.encoding));
    }
 else {
      entryInfo.comment=comment;
      feedEncodingAccumulator(encodingAccumulator,comment);
    }
    entryInfo.centralHeaderLen=46 + fileNameLen + extraLen+ commentLen;
    ze.setEntryInfo(entryInfo);
    entries.add(ze);
    nameMap.put(ze.getName(),ze);
    rais.readFully(signatureBytes);
    sig=ZipLong.getValue(signatureBytes);
  }
  if (encodingAccumulator != null && encodingAccumulator.size() > 0) {
    int nbEntries=entries.size();
    String guessedEncoding=EncodingDetector.detectEncoding(encodingAccumulator.toByteArray());
    if (Debug.ON)     Debug.trace("String_Node_Str" + guessedEncoding);
    ZipEntry entry;
    ZipEntryInfo entryInfo;
    for (int i=0; i < nbEntries; i++) {
      entry=(ZipEntry)entries.elementAt(i);
      entryInfo=entry.getEntryInfo();
      if (entryInfo.encoding != null)       continue;
      entryInfo.encoding=guessedEncoding;
      setFilename(entry,getString(entryInfo.filename,guessedEncoding));
      entryInfo.filename=null;
      entry.setComment(getString(entryInfo.comment,guessedEncoding));
      entryInfo.comment=null;
    }
  }
}