This currently can't be changed via a tunable because the
InputSourceDataInputStreams don't have access to tunables. They are
created by the user and users don't have access to tunables. We could
make them available, or perhaps change it so the DataProcessor becomes a
factory for creating InputSourceDataInptuStreams, in which case we could
pass in tunables.

These limits are currently only available as parameters to the
BucketingInputSource (the class that handles this caching behavior), but
they aren't exposed via the JAPI/SAPI, so right now there's really no
way to change them using the documented API.

So this limit is essentially hard coded right now.

Another option would be to just make the above changes so this limit
could be changed.

But I think perhaps the biggest issue is that if you want a very large
specified length complex type, we currently read that entire complex
type into memory, even if all the individual components that make up
that type are small. So this limits streamabilty with large specified
length complex types.

On 9/11/20 2:51 PM, Beckerle, Mike wrote:
> We have tunable limits people have to sometimes enlarge. E.g. max size of a 
> regex match is limited.
> 
> The DFDL spec allows implementations to have limits on backtracking 
> capability, it just requires us to document them.
> 
> That said. We really don't want to have this sort of limit hard coded.
> 
> A non-streamable file format that just stores the total length in a header 
> record is pretty common, and people will use those for really big pieces of 
> data these days.
> 
> Can this 256MB just be a tunable constant that people can enlarge?
> 
> From a security perspective, a stored length field is always something that 
> should be sanity checked - if clobbered, it could contain -1 and that could 
> be interpreted as maxInt or something, resulting in a denial-of-service 
> attack. It would be better to get a processing error in that case.
> 
> Can we just check for complex type lengths against a tunable limit, and error 
> out before we even try to read it in?
> 
> ________________________________
> From: Sloane, Brandon <bslo...@owlcyberdefense.com>
> Sent: Friday, September 11, 2020 1:53 PM
> To: dev@daffodil.apache.org <dev@daffodil.apache.org>
> Subject: Re: Large dfdl:length values on complex types
> 
> 256MB doesn't strike me as that big. We haven't ad filesize limits measured 
> in GB since fat32 and ext1 (depending on settings; even ext4 can have a limit 
> as low as 16gb). All it takes is such a file to have a length prefix, and we 
> can very easily run into the limit. Combined with our support of large binary 
> blobs, it is not unreasonable that someone would want to use DFDL on such a 
> format.
> 
> ________________________________
> From: Beckerle, Mike <mbecke...@owlcyberdefense.com>
> Sent: Friday, September 11, 2020 1:24 PM
> To: dev@daffodil.apache.org <dev@daffodil.apache.org>
> Subject: Re: Large dfdl:length values on complex types
> 
> Maybe a silly question, but why don't we just hit a tunable size limit 
> immediately before we "try to read" that data? 256MB is very big.
> 
> Is this a real format, or a test case designed to push the boundaries?
> 
> 
> ________________________________
> From: Steve Lawrence <slawre...@apache.org>
> Sent: Friday, September 11, 2020 1:14 PM
> To: dev@daffodil.apache.org <dev@daffodil.apache.org>
> Subject: Large dfdl:length values on complex types
> 
> I recently came across an issue where we have something like this:
> 
>   <xs:element name="length" type="xs:int" ... />
>   <xs:element name="data"
>     dfdl:lengthKind="explicit" dfdl:length="{ ../length }">
>     <xs:complexType>
>       <xs:sequence>
>         <xs:element name="field1" ... />
>         <xs:element name="field2" ... />
>         ...
>         <xs:element name="fieldN" ... />
>       </xs:sequence>
>     </xs:complexType>
>   </xs:element>
> 
> So we have a length element and a complex data field that uses this
> length, and the data field is made up of a bunch of fields.
> 
> The issue I come across is related to how we cache bytes in buckets for
> backtracking. As we fill up buckets, we currently limit the total amount
> cache size of the buckets to 256MB. So if someone ever parses more than
> 256MB of data and then tries to backtrack past that, we error. The idea
> being that we don't want to keep an infinite cache for potential
> backtracking and people should have realized that they went down the
> wrong branch much earlier.
> 
> Though, a problem occurs with the complex types with a large specified
> length like above. When we have the complex type with expression
> ../length, before trying to parse any of the fields, we read that length
> number of bytes into our cache buckets to confirm that that number of
> bytes exists. The problem occurs if length is more than 256MB. In this
> case, we read length number of bytes, and start removing elements from
> the cache once we read more than 256MB.
> 
> But once that succeeds and we read length bytes, we then try to start
> parsing the fields within the complex type, but we've removed those
> early cached bytes, and so we fail with an unhelpful backtracking exception.
> 
> I'm not sure of the right solution here.
> 
> Perhaps we shouldn't be throwing away these bytes when dealing with
> complex lengths?
> 
> Or perhaps we shouldn't even be trying to determine if that many bytes
> are available when we have a specified length. Instead, maybe we should
> just set the bit limit to make sure we don't parse more than than that?
> And if eventually something tries to read a byte and there aren't enough
> and we hit that limit, only then do we fail. This feels like the right
> solution, but wanted to start a discussion to see if maybe there's a
> reason we try to read the full length, or maybe there's another alternative?
> 

Reply via email to