@@ -157,6 +157,81 @@ public function testParseAnswerWithInlineData()
157157 $ this ->assertSame ('178.79.169.131 ' , $ response ->answers [0 ]->data );
158158 }
159159
160+ public function testParseAnswerWithExcessiveTtlReturnsZeroTtl ()
161+ {
162+ $ data = "" ;
163+ $ data .= "04 69 67 6f 72 02 69 6f 00 " ; // answer: igor.io
164+ $ data .= "00 01 00 01 " ; // answer: type A, class IN
165+ $ data .= "ff ff ff ff " ; // answer: ttl 2^32 - 1
166+ $ data .= "00 04 " ; // answer: rdlength 4
167+ $ data .= "b2 4f a9 83 " ; // answer: rdata 178.79.169.131
168+
169+ $ data = $ this ->convertTcpDumpToBinary ($ data );
170+
171+ $ response = new Message ();
172+ $ response ->header ->set ('anCount ' , 1 );
173+ $ response ->data = $ data ;
174+
175+ $ this ->parser ->parseAnswer ($ response );
176+
177+ $ this ->assertCount (1 , $ response ->answers );
178+ $ this ->assertSame ('igor.io ' , $ response ->answers [0 ]->name );
179+ $ this ->assertSame (Message::TYPE_A , $ response ->answers [0 ]->type );
180+ $ this ->assertSame (Message::CLASS_IN , $ response ->answers [0 ]->class );
181+ $ this ->assertSame (0 , $ response ->answers [0 ]->ttl );
182+ $ this ->assertSame ('178.79.169.131 ' , $ response ->answers [0 ]->data );
183+ }
184+
185+ public function testParseAnswerWithTtlExactlyBoundaryReturnsZeroTtl ()
186+ {
187+ $ data = "" ;
188+ $ data .= "04 69 67 6f 72 02 69 6f 00 " ; // answer: igor.io
189+ $ data .= "00 01 00 01 " ; // answer: type A, class IN
190+ $ data .= "80 00 00 00 " ; // answer: ttl 2^31
191+ $ data .= "00 04 " ; // answer: rdlength 4
192+ $ data .= "b2 4f a9 83 " ; // answer: rdata 178.79.169.131
193+
194+ $ data = $ this ->convertTcpDumpToBinary ($ data );
195+
196+ $ response = new Message ();
197+ $ response ->header ->set ('anCount ' , 1 );
198+ $ response ->data = $ data ;
199+
200+ $ this ->parser ->parseAnswer ($ response );
201+
202+ $ this ->assertCount (1 , $ response ->answers );
203+ $ this ->assertSame ('igor.io ' , $ response ->answers [0 ]->name );
204+ $ this ->assertSame (Message::TYPE_A , $ response ->answers [0 ]->type );
205+ $ this ->assertSame (Message::CLASS_IN , $ response ->answers [0 ]->class );
206+ $ this ->assertSame (0 , $ response ->answers [0 ]->ttl );
207+ $ this ->assertSame ('178.79.169.131 ' , $ response ->answers [0 ]->data );
208+ }
209+
210+ public function testParseAnswerWithMaximumTtlReturnsExactTtl ()
211+ {
212+ $ data = "" ;
213+ $ data .= "04 69 67 6f 72 02 69 6f 00 " ; // answer: igor.io
214+ $ data .= "00 01 00 01 " ; // answer: type A, class IN
215+ $ data .= "7f ff ff ff " ; // answer: ttl 2^31 - 1
216+ $ data .= "00 04 " ; // answer: rdlength 4
217+ $ data .= "b2 4f a9 83 " ; // answer: rdata 178.79.169.131
218+
219+ $ data = $ this ->convertTcpDumpToBinary ($ data );
220+
221+ $ response = new Message ();
222+ $ response ->header ->set ('anCount ' , 1 );
223+ $ response ->data = $ data ;
224+
225+ $ this ->parser ->parseAnswer ($ response );
226+
227+ $ this ->assertCount (1 , $ response ->answers );
228+ $ this ->assertSame ('igor.io ' , $ response ->answers [0 ]->name );
229+ $ this ->assertSame (Message::TYPE_A , $ response ->answers [0 ]->type );
230+ $ this ->assertSame (Message::CLASS_IN , $ response ->answers [0 ]->class );
231+ $ this ->assertSame (0x7fffffff , $ response ->answers [0 ]->ttl );
232+ $ this ->assertSame ('178.79.169.131 ' , $ response ->answers [0 ]->data );
233+ }
234+
160235 public function testParseAnswerWithUnknownType ()
161236 {
162237 $ data = "" ;
0 commit comments