Program: 11794
Project: 11794
Buggy source:
/** 
 * Pass in a chunk to save its data to the file
 */
public void saveChunkData(TridentChunk chunk) throws IOException, NBTException {
  ByteArrayOutputStream nbtStream=new ByteArrayOutputStream();
  new NBTEncoder(new DataOutputStream(nbtStream)).encode(chunk.asNbt());
  byte[] uncompressed=nbtStream.toByteArray();
  Deflater deflater=new Deflater();
  ByteArrayOutputStream os=new ByteArrayOutputStream();
  deflater.setInput(uncompressed);
  deflater.finish();
  while (!deflater.finished()) {
    int bytes=deflater.deflate(buffer);
    os.write(buffer,0,bytes);
  }
  byte[] compressed=os.toByteArray();
  int actualLength=compressed.length + 1;
  int sectorLength=IntMath.divide(actualLength,SectorStorage.SECTOR_LENGTH,RoundingMode.CEILING);
  int oldSectorLength=this.sectors.dataSectors(chunk);
  if (sectorLength < oldSectorLength) {
    this.sectors.setDataSectors(chunk,sectors.rawOffset(chunk) | sectorLength);
    this.sectors.freeSectors(this.sectors.sectorOffset(chunk) + sectorLength - 1,oldSectorLength - sectorLength);
  }
 else   if (sectorLength > oldSectorLength) {
    this.sectors.setDataSectors(chunk,sectors.rawOffset(chunk) | sectorLength);
    this.sectors.freeSectors(this.sectors.sectorOffset(chunk),oldSectorLength);
    this.sectors.setSectorOffset(chunk,this.sectors.findFreeSectors(sectorLength));
  }
  this.sectors.addSectors(this.sectors.sectorOffset(chunk),this.sectors.dataSectors(chunk));
synchronized (this.readWriteLock) {
    RandomAccessFile access=new RandomAccessFile(this.path.toFile(),"String_Node_Str");
    long dataLoc=(long)this.sectors.dataLoc(chunk);
    access.seek(dataLoc);
    access.writeInt(actualLength);
    access.write((int)(byte)2);
    access.write(compressed);
    int paddingNeeded=actualLength % SectorStorage.SECTOR_LENGTH;
    if (paddingNeeded != 0) {
      byte[] padding=new byte[paddingNeeded];
      access.write(padding);
    }
    access.seek((long)(this.sectors.offsetLoc(chunk)));
    access.write(this.sectors.rawOffset(chunk));
    this.packFile(access);
    access.close();
  }
}

Fixed version (ground truth):
/** 
 * Pass in a chunk to save its data to the file
 */
public void saveChunkData(TridentChunk chunk) throws IOException, NBTException {
  CompoundTag tag=chunk.asNbt();
  ByteArrayOutputStream nbtStream=new ByteArrayOutputStream();
  new NBTEncoder(new DataOutputStream(nbtStream)).encode(tag);
  byte[] uncompressed=nbtStream.toByteArray();
  Deflater deflater=new Deflater();
  ByteArrayOutputStream os=new ByteArrayOutputStream();
  deflater.setInput(uncompressed);
  deflater.finish();
  while (!deflater.finished()) {
    int bytes=deflater.deflate(buffer);
    os.write(buffer,0,bytes);
  }
  byte[] compressed=os.toByteArray();
  int actualLength=compressed.length + 1;
  int sectorLength=IntMath.divide(actualLength,SectorStorage.SECTOR_LENGTH,RoundingMode.CEILING);
  int oldSectorLength=this.sectors.dataSectors(chunk);
  if (sectorLength < oldSectorLength) {
    this.sectors.setDataSectors(chunk,sectors.rawOffset(chunk) | sectorLength);
    this.sectors.freeSectors(this.sectors.sectorOffset(chunk) + sectorLength - 1,oldSectorLength - sectorLength);
  }
 else   if (sectorLength > oldSectorLength) {
    this.sectors.setDataSectors(chunk,sectors.rawOffset(chunk) | sectorLength);
    this.sectors.freeSectors(this.sectors.sectorOffset(chunk),oldSectorLength);
    int newLocation=sectors.findFreeSectors(sectorLength);
    int hashCode=hashCode();
    int offsetLoc=sectors.offsetLoc(chunk);
    sectors.offsets[offsetLoc]=(newLocation << 8);
    sectors.addSectors(newLocation,sectorLength);
  }
synchronized (this.readWriteLock) {
    RandomAccessFile access=new RandomAccessFile(this.path.toFile(),"String_Node_Str");
    long dataLoc=(long)this.sectors.dataLoc(chunk);
    access.seek(dataLoc);
    access.writeInt(actualLength);
    access.write((int)(byte)2);
    access.write(compressed);
    int paddingNeeded=actualLength % SectorStorage.SECTOR_LENGTH;
    if (paddingNeeded != 0) {
      byte[] padding=new byte[paddingNeeded];
      access.write(padding);
    }
    access.seek((long)(this.sectors.offsetLoc(chunk)));
    access.write(this.sectors.rawOffset(chunk));
    this.packFile(access);
    access.seek((long)sectors.timeStampLoc(chunk));
    access.writeInt((int)(System.currentTimeMillis() / 1000L));
    access.close();
  }
}