Buggy code:
public class TSIG { public static final Name HMAC = Name . fromConstantString ( "HMAC-MD5.SIG-ALG.REG.INT." ) ; public static final short FUDGE = 300 ; private Name name ; private Name alg ; private byte [ ] key ; public TSIG ( Name name , byte [ ] key ) { } public TSIG ( String name , String key ) { } public TSIGRecord generate ( Message m , byte [ ] b , byte error , TSIGRecord old ) { } public void apply ( Message m , byte error , TSIGRecord old ) { } public void apply ( Message m , TSIGRecord old ) { } public void applyStream ( Message m , TSIGRecord old , boolean first ) { } public byte verify ( Message m , byte [ ] b , int length , TSIGRecord old ) { TSIGRecord tsig = m . getTSIG ( ) ; hmacSigner h = new hmacSigner ( key ) ; if ( tsig == null ) return Rcode . FORMERR ; if ( ( ! ( tsig . getName ( ) . equals ( name ) ) ) || ( ! ( tsig . getAlgorithm ( ) . equals ( alg ) ) ) ) { if ( Options . check ( "verbose" ) ) System . err . println ( "BADKEY<seq2seq4repair_space>failure" ) ; return Rcode . BADKEY ; } long now = System . currentTimeMillis ( ) ; long then = tsig . getTimeSigned ( ) . getTime ( ) ; long fudge = tsig . getFudge ( ) ; if ( ( Math . abs ( ( now - then ) ) ) > ( fudge * 1000 ) ) { if ( Options . check ( "verbose" ) ) System . err . println ( "BADTIME<seq2seq4repair_space>failure" ) ; return Rcode . BADTIME ; } try { if ( ( ( old != null ) && ( ( tsig . getError ( ) ) != ( Rcode . BADKEY ) ) ) && ( ( tsig . getError ( ) ) != ( Rcode . BADSIG ) ) ) { DataByteOutputStream dbs = new DataByteOutputStream ( ) ; dbs . writeShort ( ( ( short ) ( old . getSignature ( ) . length ) ) ) ; h . addData ( dbs . toByteArray ( ) ) ; h . addData ( old . getSignature ( ) ) ; } m . getHeader ( ) . decCount ( ADDITIONAL ) ; byte [ ] header = m . getHeader ( ) . toWire ( ) ; m . getHeader ( ) . incCount ( ADDITIONAL ) ; h . addData ( header ) ; int len = ( m . tsigstart ) - ( header . length ) ; h . addData ( b , header . length , len ) ; DataByteOutputStream out = new DataByteOutputStream ( ) ; tsig . getName ( ) . toWireCanonical ( out ) ; out . writeShort ( tsig . dclass ) ; <START_BUG> out . writeInt ( tsig . ttl ) ; <END_BUG> tsig . getAlgorithm ( ) . toWireCanonical ( out ) ; long time = ( tsig . getTimeSigned ( ) . getTime ( ) ) // 1000 ; short timeHigh = ( ( short ) ( time > > 32 ) ) ; int timeLow = ( ( int ) ( time ) ) ; out . writeShort ( timeHigh ) ; out . writeInt ( timeLow ) ; out . writeShort ( tsig . getFudge ( ) ) ; out . writeShort ( tsig . getError ( ) ) ; if ( ( tsig . getOther ( ) ) != null ) { out . writeShort ( tsig . getOther ( ) . length ) ; out . write ( tsig . getOther ( ) ) ; } else out . writeShort ( 0 ) ; h . addData ( out . toByteArray ( ) ) ; } catch ( IOException e ) { return Rcode . SERVFAIL ; } if ( h . verify ( tsig . getSignature ( ) ) ) return Rcode . NOERROR ; else { if ( Options . check ( "verbose" ) ) System . err . println ( "BADSIG<seq2seq4repair_space>failure" ) ; return Rcode . BADSIG ; } } public byte verify ( Message m , byte [ ] b , TSIGRecord old ) { } public int recordLength ( ) { } public static class StreamVerifier { private TSIG key ; private hmacSigner verifier ; private int nresponses ; private int lastsigned ; private TSIGRecord lastTSIG ; public StreamVerifier ( TSIG tsig , TSIGRecord old ) { } public byte verify ( Message m , byte [ ] b ) { } } }

Fix:
out . writeUnsignedInt ( tsig . ttl ) ;