Program: 4371
Project: 4371
Buggy source:
private void writeEpilog() throws IOException {
  Date modificationTime=new Date();
  int duration=0;
  for (  Sample s : videoFrames) {
    duration+=s.duration;
  }
  DataAtom leaf;
  CompositeAtom moovAtom=new CompositeAtom("String_Node_Str");
  leaf=new DataAtom("String_Node_Str");
  moovAtom.add(leaf);
  DataAtomOutputStream d=leaf.getOutputStream();
  d.writeByte(0);
  d.writeByte(0);
  d.writeByte(0);
  d.writeByte(0);
  d.writeMacTimestamp(creationTime);
  d.writeMacTimestamp(modificationTime);
  d.writeInt(timeScale);
  d.writeInt(duration);
  d.writeFixed16D16(1d);
  d.writeShort(256);
  d.write(new byte[10]);
  d.writeFixed16D16(1f);
  d.writeFixed16D16(0f);
  d.writeFixed2D30(0f);
  d.writeFixed16D16(0f);
  d.writeFixed16D16(1f);
  d.writeFixed2D30(0);
  d.writeFixed16D16(0);
  d.writeFixed16D16(0);
  d.writeFixed2D30(1f);
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(2);
  CompositeAtom trakAtom=new CompositeAtom("String_Node_Str");
  moovAtom.add(trakAtom);
  leaf=new DataAtom("String_Node_Str");
  trakAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0xf);
  d.writeMacTimestamp(creationTime);
  d.writeMacTimestamp(modificationTime);
  d.writeInt(1);
  d.writeInt(0);
  d.writeInt(duration);
  d.writeLong(0);
  d.writeShort(0);
  d.writeShort(0);
  d.writeShort(0);
  d.writeShort(0);
  d.writeFixed16D16(1f);
  d.writeFixed16D16(0f);
  d.writeFixed2D30(0f);
  d.writeFixed16D16(0f);
  d.writeFixed16D16(1f);
  d.writeFixed2D30(0);
  d.writeFixed16D16(0);
  d.writeFixed16D16(0);
  d.writeFixed2D30(1f);
  d.writeFixed16D16(imgWidth);
  d.writeFixed16D16(imgHeight);
  CompositeAtom mdiaAtom=new CompositeAtom("String_Node_Str");
  trakAtom.add(mdiaAtom);
  leaf=new DataAtom("String_Node_Str");
  mdiaAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0);
  d.writeMacTimestamp(creationTime);
  d.writeMacTimestamp(modificationTime);
  d.writeInt(timeScale);
  d.writeInt(duration);
  d.writeShort(0);
  d.writeShort(0);
  leaf=new DataAtom("String_Node_Str");
  mdiaAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0);
  d.writeType("String_Node_Str");
  d.writeType("String_Node_Str");
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(0);
  d.write(0);
  CompositeAtom minfAtom=new CompositeAtom("String_Node_Str");
  mdiaAtom.add(minfAtom);
  leaf=new DataAtom("String_Node_Str");
  minfAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0x1);
  d.writeShort(0x40);
  d.writeUShort(0);
  d.writeUShort(0);
  d.writeUShort(0);
  leaf=new DataAtom("String_Node_Str");
  minfAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0);
  d.writeType("String_Node_Str");
  d.writeType("String_Node_Str");
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(0);
  d.write(0);
  CompositeAtom dinfAtom=new CompositeAtom("String_Node_Str");
  minfAtom.add(dinfAtom);
  leaf=new DataAtom("String_Node_Str");
  dinfAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0);
  d.writeInt(1);
  d.writeInt(12);
  d.writeType("String_Node_Str");
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0x1);
  CompositeAtom stblAtom=new CompositeAtom("String_Node_Str");
  minfAtom.add(stblAtom);
  leaf=new DataAtom("String_Node_Str");
  stblAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0);
  d.writeInt(1);
switch (videoFormat) {
case RAW:
{
      d.writeInt(86);
      d.writeType("String_Node_Str");
      d.write(new byte[6]);
      d.writeShort(1);
      d.writeShort(0);
      d.writeShort(0);
      d.writeType("String_Node_Str");
      d.writeInt(0);
      d.writeInt(512);
      d.writeUShort(imgWidth);
      d.writeUShort(imgHeight);
      d.writeFixed16D16(72.0);
      d.writeFixed16D16(72.0);
      d.writeInt(0);
      d.writeShort(1);
      d.writePString("String_Node_Str",32);
      d.writeShort(24);
      d.writeShort(-1);
      break;
    }
case JPG:
{
    d.writeInt(86);
    d.writeType("String_Node_Str");
    d.write(new byte[6]);
    d.writeShort(1);
    d.writeShort(0);
    d.writeShort(0);
    d.writeType("String_Node_Str");
    d.writeInt(0);
    d.writeInt(512);
    d.writeUShort(imgWidth);
    d.writeUShort(imgHeight);
    d.writeFixed16D16(72.0);
    d.writeFixed16D16(72.0);
    d.writeInt(0);
    d.writeShort(1);
    d.writePString("String_Node_Str",32);
    d.writeShort(24);
    d.writeShort(-1);
    break;
  }
case PNG:
{
  d.writeInt(86);
  d.writeType("String_Node_Str");
  d.write(new byte[6]);
  d.writeShort(1);
  d.writeShort(0);
  d.writeShort(0);
  d.writeType("String_Node_Str");
  d.writeInt(0);
  d.writeInt(512);
  d.writeUShort(imgWidth);
  d.writeUShort(imgHeight);
  d.writeFixed16D16(72.0);
  d.writeFixed16D16(72.0);
  d.writeInt(0);
  d.writeShort(1);
  d.writePString("String_Node_Str",32);
  d.writeShort(24);
  d.writeShort(-1);
  break;
}
}
leaf=new DataAtom("String_Node_Str");
stblAtom.add(leaf);
d=leaf.getOutputStream();
d.write(0);
d.write(0);
d.write(0);
d.write(0);
int runCount=1;
int prevDuration=videoFrames.size() == 0 ? 0 : videoFrames.get(0).duration;
for (Sample s : videoFrames) {
if (s.duration != prevDuration) {
runCount++;
prevDuration=s.duration;
}
}
d.writeInt(runCount);
int runLength=0;
prevDuration=videoFrames.size() == 0 ? 0 : videoFrames.get(0).duration;
for (Sample s : videoFrames) {
if (s.duration != prevDuration) {
if (runLength > 0) {
  d.writeInt(runLength);
  d.writeInt(prevDuration);
}
prevDuration=s.duration;
runLength=1;
}
 else {
runLength++;
}
}
if (runLength > 0) {
d.writeInt(runLength);
d.writeInt(prevDuration);
}
leaf=new DataAtom("String_Node_Str");
stblAtom.add(leaf);
d=leaf.getOutputStream();
d.write(0);
d.write(0);
d.write(0);
d.write(0);
d.writeInt(1);
d.writeInt(1);
d.writeInt(1);
d.writeInt(1);
leaf=new DataAtom("String_Node_Str");
stblAtom.add(leaf);
d=leaf.getOutputStream();
d.write(0);
d.write(0);
d.write(0);
d.write(0);
d.writeUInt(0);
d.writeUInt(videoFrames.size());
for (Sample s : videoFrames) {
d.writeUInt(s.length);
}
if (videoFrames.size() == 0 || videoFrames.getLast().offset <= 0xffffffffL) {
leaf=new DataAtom("String_Node_Str");
stblAtom.add(leaf);
d=leaf.getOutputStream();
d.write(0);
d.write(0);
d.write(0);
d.write(0);
d.writeUInt(videoFrames.size());
for (Sample s : videoFrames) {
d.writeUInt(s.offset);
}
}
 else {
leaf=new DataAtom("String_Node_Str");
stblAtom.add(leaf);
d=leaf.getOutputStream();
d.write(0);
d.write(0);
d.write(0);
d.write(0);
d.writeUInt(videoFrames.size());
for (Sample s : videoFrames) {
d.writeLong(s.offset);
}
}
moovAtom.finish();
}

Fixed version (ground truth):
private void writeEpilog() throws IOException {
  Date modificationTime=new Date();
  int duration=0;
  for (  Sample s : videoFrames) {
    duration+=s.duration;
  }
  DataAtom leaf;
  CompositeAtom moovAtom=new CompositeAtom("String_Node_Str");
  leaf=new DataAtom("String_Node_Str");
  moovAtom.add(leaf);
  DataAtomOutputStream d=leaf.getOutputStream();
  d.writeByte(0);
  d.writeByte(0);
  d.writeByte(0);
  d.writeByte(0);
  d.writeMacTimestamp(creationTime);
  d.writeMacTimestamp(modificationTime);
  d.writeInt(timeScale);
  d.writeInt(duration);
  d.writeFixed16D16(1d);
  d.writeShort(256);
  d.write(new byte[10]);
  d.writeFixed16D16(1f);
  d.writeFixed16D16(0f);
  d.writeFixed2D30(0f);
  d.writeFixed16D16(0f);
  d.writeFixed16D16(1f);
  d.writeFixed2D30(0);
  d.writeFixed16D16(0);
  d.writeFixed16D16(0);
  d.writeFixed2D30(1f);
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(2);
  CompositeAtom trakAtom=new CompositeAtom("String_Node_Str");
  moovAtom.add(trakAtom);
  leaf=new DataAtom("String_Node_Str");
  trakAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0xf);
  d.writeMacTimestamp(creationTime);
  d.writeMacTimestamp(modificationTime);
  d.writeInt(1);
  d.writeInt(0);
  d.writeInt(duration);
  d.writeLong(0);
  d.writeShort(0);
  d.writeShort(0);
  d.writeShort(0);
  d.writeShort(0);
  d.writeFixed16D16(1f);
  d.writeFixed16D16(0f);
  d.writeFixed2D30(0f);
  d.writeFixed16D16(0f);
  d.writeFixed16D16(1f);
  d.writeFixed2D30(0);
  d.writeFixed16D16(0);
  d.writeFixed16D16(0);
  d.writeFixed2D30(1f);
  d.writeFixed16D16(imgWidth);
  d.writeFixed16D16(imgHeight);
  CompositeAtom mdiaAtom=new CompositeAtom("String_Node_Str");
  trakAtom.add(mdiaAtom);
  leaf=new DataAtom("String_Node_Str");
  mdiaAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0);
  d.writeMacTimestamp(creationTime);
  d.writeMacTimestamp(modificationTime);
  d.writeInt(timeScale);
  d.writeInt(duration);
  d.writeShort(0);
  d.writeShort(0);
  leaf=new DataAtom("String_Node_Str");
  mdiaAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0);
  d.writeType("String_Node_Str");
  d.writeType("String_Node_Str");
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(0);
  d.write(0);
  CompositeAtom minfAtom=new CompositeAtom("String_Node_Str");
  mdiaAtom.add(minfAtom);
  leaf=new DataAtom("String_Node_Str");
  minfAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0x1);
  d.writeShort(0x40);
  d.writeUShort(0);
  d.writeUShort(0);
  d.writeUShort(0);
  leaf=new DataAtom("String_Node_Str");
  minfAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0);
  d.writeType("String_Node_Str");
  d.writeType("String_Node_Str");
  d.writeInt(0);
  d.writeInt(0);
  d.writeInt(0);
  d.write(0);
  CompositeAtom dinfAtom=new CompositeAtom("String_Node_Str");
  minfAtom.add(dinfAtom);
  leaf=new DataAtom("String_Node_Str");
  dinfAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0);
  d.writeInt(1);
  d.writeInt(12);
  d.writeType("String_Node_Str");
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0x1);
  CompositeAtom stblAtom=new CompositeAtom("String_Node_Str");
  minfAtom.add(stblAtom);
  leaf=new DataAtom("String_Node_Str");
  stblAtom.add(leaf);
  d=leaf.getOutputStream();
  d.write(0);
  d.write(0);
  d.write(0);
  d.write(0);
  d.writeInt(1);
switch (videoFormat) {
case RAW:
{
      d.writeInt(86);
      d.writeType("String_Node_Str");
      d.write(new byte[6]);
      d.writeShort(1);
      d.writeShort(0);
      d.writeShort(0);
      d.writeType("String_Node_Str");
      d.writeInt(0);
      d.writeInt(512);
      d.writeUShort(imgWidth);
      d.writeUShort(imgHeight);
      d.writeFixed16D16(72.0);
      d.writeFixed16D16(72.0);
      d.writeInt(0);
      d.writeShort(1);
      d.writePString("String_Node_Str",32);
      d.writeShort(24);
      d.writeShort(-1);
      break;
    }
case JPG:
{
    d.writeInt(86);
    d.writeType("String_Node_Str");
    d.write(new byte[6]);
    d.writeShort(1);
    d.writeShort(0);
    d.writeShort(0);
    d.writeType("String_Node_Str");
    d.writeInt(0);
    d.writeInt(512);
    d.writeUShort(imgWidth);
    d.writeUShort(imgHeight);
    d.writeFixed16D16(72.0);
    d.writeFixed16D16(72.0);
    d.writeInt(0);
    d.writeShort(1);
    d.writePString("String_Node_Str",32);
    d.writeShort(24);
    d.writeShort(-1);
    break;
  }
case PNG:
{
  d.writeInt(86);
  d.writeType("String_Node_Str");
  d.write(new byte[6]);
  d.writeShort(1);
  d.writeShort(0);
  d.writeShort(0);
  d.writeType("String_Node_Str");
  d.writeInt(0);
  d.writeInt(512);
  d.writeUShort(imgWidth);
  d.writeUShort(imgHeight);
  d.writeFixed16D16(72.0);
  d.writeFixed16D16(72.0);
  d.writeInt(0);
  d.writeShort(1);
  d.writePString("String_Node_Str",32);
  d.writeShort(24);
  d.writeShort(-1);
  break;
}
default :
throw new IllegalStateException("String_Node_Str" + videoFormat);
}
leaf=new DataAtom("String_Node_Str");
stblAtom.add(leaf);
d=leaf.getOutputStream();
d.write(0);
d.write(0);
d.write(0);
d.write(0);
int runCount=1;
int prevDuration=videoFrames.size() == 0 ? 0 : videoFrames.get(0).duration;
for (Sample s : videoFrames) {
if (s.duration != prevDuration) {
runCount++;
prevDuration=s.duration;
}
}
d.writeInt(runCount);
int runLength=0;
prevDuration=videoFrames.size() == 0 ? 0 : videoFrames.get(0).duration;
for (Sample s : videoFrames) {
if (s.duration != prevDuration) {
if (runLength > 0) {
d.writeInt(runLength);
d.writeInt(prevDuration);
}
prevDuration=s.duration;
runLength=1;
}
 else {
runLength++;
}
}
if (runLength > 0) {
d.writeInt(runLength);
d.writeInt(prevDuration);
}
leaf=new DataAtom("String_Node_Str");
stblAtom.add(leaf);
d=leaf.getOutputStream();
d.write(0);
d.write(0);
d.write(0);
d.write(0);
d.writeInt(1);
d.writeInt(1);
d.writeInt(1);
d.writeInt(1);
leaf=new DataAtom("String_Node_Str");
stblAtom.add(leaf);
d=leaf.getOutputStream();
d.write(0);
d.write(0);
d.write(0);
d.write(0);
d.writeUInt(0);
d.writeUInt(videoFrames.size());
for (Sample s : videoFrames) {
d.writeUInt(s.length);
}
if (videoFrames.size() == 0 || videoFrames.getLast().offset <= 0xffffffffL) {
leaf=new DataAtom("String_Node_Str");
stblAtom.add(leaf);
d=leaf.getOutputStream();
d.write(0);
d.write(0);
d.write(0);
d.write(0);
d.writeUInt(videoFrames.size());
for (Sample s : videoFrames) {
d.writeUInt(s.offset);
}
}
 else {
leaf=new DataAtom("String_Node_Str");
stblAtom.add(leaf);
d=leaf.getOutputStream();
d.write(0);
d.write(0);
d.write(0);
d.write(0);
d.writeUInt(videoFrames.size());
for (Sample s : videoFrames) {
d.writeLong(s.offset);
}
}
moovAtom.finish();
}