Program: 110176
Project: 110176
Buggy source:
private boolean readAtomHeader(ExtractorInput input) throws IOException, InterruptedException {
  if (atomHeaderBytesRead == 0) {
    if (!input.readFully(atomHeader.data,0,Atom.HEADER_SIZE,true)) {
      return false;
    }
    atomHeaderBytesRead=Atom.HEADER_SIZE;
    atomHeader.setPosition(0);
    atomSize=atomHeader.readUnsignedInt();
    atomType=atomHeader.readInt();
  }
  if (atomSize == Atom.DEFINES_LARGE_SIZE) {
    int headerBytesRemaining=Atom.LONG_HEADER_SIZE - Atom.HEADER_SIZE;
    input.readFully(atomHeader.data,Atom.HEADER_SIZE,headerBytesRemaining);
    atomHeaderBytesRead+=headerBytesRemaining;
    atomSize=atomHeader.readUnsignedLongToLong();
  }
 else   if (atomSize == Atom.EXTENDS_TO_END_SIZE) {
    long endPosition=input.getLength();
    if (endPosition == C.LENGTH_UNSET && !containerAtoms.isEmpty()) {
      endPosition=containerAtoms.peek().endPosition;
    }
    if (endPosition != C.LENGTH_UNSET) {
      atomSize=endPosition - input.getPosition() + atomHeaderBytesRead;
    }
  }
  if (atomSize < atomHeaderBytesRead) {
    throw new ParserException("String_Node_Str");
  }
  long atomPosition=input.getPosition() - atomHeaderBytesRead;
  if (atomType == Atom.TYPE_moof) {
    int trackCount=trackBundles.size();
    for (int i=0; i < trackCount; i++) {
      TrackFragment fragment=trackBundles.valueAt(i).fragment;
      fragment.atomPosition=atomPosition;
      fragment.auxiliaryDataPosition=atomPosition;
      fragment.dataPosition=atomPosition;
    }
  }
  if (atomType == Atom.TYPE_mdat) {
    currentTrackBundle=null;
    endOfMdatPosition=atomPosition + atomSize;
    if (!haveOutputSeekMap) {
      extractorOutput.seekMap(new SeekMap.Unseekable(durationUs,atomPosition));
      haveOutputSeekMap=true;
    }
    parserState=STATE_READING_ENCRYPTION_DATA;
    return true;
  }
  if (shouldParseContainerAtom(atomType)) {
    long endPosition=input.getPosition() + atomSize - Atom.HEADER_SIZE;
    containerAtoms.add(new ContainerAtom(atomType,endPosition));
    if (atomSize == atomHeaderBytesRead) {
      processAtomEnded(endPosition);
    }
 else {
      enterReadingAtomHeaderState();
    }
  }
 else   if (shouldParseLeafAtom(atomType)) {
    if (atomHeaderBytesRead != Atom.HEADER_SIZE) {
      throw new ParserException("String_Node_Str");
    }
    if (atomSize > Integer.MAX_VALUE) {
      throw new ParserException("String_Node_Str");
    }
    atomData=new ParsableByteArray((int)atomSize);
    System.arraycopy(atomHeader.data,0,atomData.data,0,Atom.HEADER_SIZE);
    parserState=STATE_READING_ATOM_PAYLOAD;
  }
 else {
    if (atomSize > Integer.MAX_VALUE) {
      throw new ParserException("String_Node_Str");
    }
    atomData=null;
    parserState=STATE_READING_ATOM_PAYLOAD;
  }
  return true;
}

Fixed version (ground truth):
private boolean readAtomHeader(ExtractorInput input) throws IOException, InterruptedException {
  if (atomHeaderBytesRead == 0) {
    if (!input.readFully(atomHeader.data,0,Atom.HEADER_SIZE,true)) {
      return false;
    }
    atomHeaderBytesRead=Atom.HEADER_SIZE;
    atomHeader.setPosition(0);
    atomSize=atomHeader.readUnsignedInt();
    atomType=atomHeader.readInt();
  }
  if (atomSize == Atom.DEFINES_LARGE_SIZE) {
    int headerBytesRemaining=Atom.LONG_HEADER_SIZE - Atom.HEADER_SIZE;
    input.readFully(atomHeader.data,Atom.HEADER_SIZE,headerBytesRemaining);
    atomHeaderBytesRead+=headerBytesRemaining;
    atomSize=atomHeader.readUnsignedLongToLong();
  }
 else   if (atomSize == Atom.EXTENDS_TO_END_SIZE) {
    long endPosition=input.getLength();
    if (endPosition == C.LENGTH_UNSET && !containerAtoms.isEmpty()) {
      endPosition=containerAtoms.peek().endPosition;
    }
    if (endPosition != C.LENGTH_UNSET) {
      atomSize=endPosition - input.getPosition() + atomHeaderBytesRead;
    }
  }
  if (atomSize < atomHeaderBytesRead) {
    throw new ParserException("String_Node_Str");
  }
  long atomPosition=input.getPosition() - atomHeaderBytesRead;
  if (atomType == Atom.TYPE_moof) {
    int trackCount=trackBundles.size();
    for (int i=0; i < trackCount; i++) {
      TrackFragment fragment=trackBundles.valueAt(i).fragment;
      fragment.atomPosition=atomPosition;
      fragment.auxiliaryDataPosition=atomPosition;
      fragment.dataPosition=atomPosition;
    }
  }
  if (atomType == Atom.TYPE_mdat) {
    currentTrackBundle=null;
    endOfMdatPosition=atomPosition + atomSize;
    if (!haveOutputSeekMap) {
      extractorOutput.seekMap(new SeekMap.Unseekable(durationUs,atomPosition));
      haveOutputSeekMap=true;
    }
    parserState=STATE_READING_ENCRYPTION_DATA;
    return true;
  }
  if (shouldParseContainerAtom(atomType)) {
    long endPosition=input.getPosition() + atomSize - Atom.HEADER_SIZE;
    containerAtoms.push(new ContainerAtom(atomType,endPosition));
    if (atomSize == atomHeaderBytesRead) {
      processAtomEnded(endPosition);
    }
 else {
      enterReadingAtomHeaderState();
    }
  }
 else   if (shouldParseLeafAtom(atomType)) {
    if (atomHeaderBytesRead != Atom.HEADER_SIZE) {
      throw new ParserException("String_Node_Str");
    }
    if (atomSize > Integer.MAX_VALUE) {
      throw new ParserException("String_Node_Str");
    }
    atomData=new ParsableByteArray((int)atomSize);
    System.arraycopy(atomHeader.data,0,atomData.data,0,Atom.HEADER_SIZE);
    parserState=STATE_READING_ATOM_PAYLOAD;
  }
 else {
    if (atomSize > Integer.MAX_VALUE) {
      throw new ParserException("String_Node_Str");
    }
    atomData=null;
    parserState=STATE_READING_ATOM_PAYLOAD;
  }
  return true;
}