@@ -71,6 +71,11 @@ class Decoder
71
71
*/
72
72
private $ decodingContextFactory ;
73
73
74
+ /**
75
+ * @var bool
76
+ */
77
+ private $ allowTrailingData ;
78
+
74
79
/**
75
80
* Constructor
76
81
*
@@ -80,21 +85,24 @@ class Decoder
80
85
* @param \LibDNS\Records\ResourceBuilder $resourceBuilder
81
86
* @param \LibDNS\Records\Types\TypeBuilder $typeBuilder
82
87
* @param \LibDNS\Decoder\DecodingContextFactory $decodingContextFactory
88
+ * @param bool $allowTrailingData
83
89
*/
84
90
public function __construct (
85
91
PacketFactory $ packetFactory ,
86
92
MessageFactory $ messageFactory ,
87
93
QuestionFactory $ questionFactory ,
88
94
ResourceBuilder $ resourceBuilder ,
89
95
TypeBuilder $ typeBuilder ,
90
- DecodingContextFactory $ decodingContextFactory
96
+ DecodingContextFactory $ decodingContextFactory ,
97
+ $ allowTrailingData = false
91
98
) {
92
99
$ this ->packetFactory = $ packetFactory ;
93
100
$ this ->messageFactory = $ messageFactory ;
94
101
$ this ->questionFactory = $ questionFactory ;
95
102
$ this ->resourceBuilder = $ resourceBuilder ;
96
103
$ this ->typeBuilder = $ typeBuilder ;
97
104
$ this ->decodingContextFactory = $ decodingContextFactory ;
105
+ $ this ->allowTrailingData = $ allowTrailingData ;
98
106
}
99
107
100
108
/**
@@ -476,7 +484,7 @@ public function decode($data)
476
484
$ additionalRecords ->add ($ this ->decodeResourceRecord ($ decodingContext ));
477
485
}
478
486
479
- if ($ packet ->getBytesRemaining () !== 0 ) {
487
+ if (! $ this -> allowTrailingData && $ packet ->getBytesRemaining () !== 0 ) {
480
488
throw new \UnexpectedValueException ('Decode error: Unexpected data at end of packet ' );
481
489
}
482
490
0 commit comments