(In reply to Jens Stutte [:jstutte] (REO for FF 81) from comment #12) > This would indicate that files of size < aprox. 2 GB can work (if we have enough memory) So looking at the [value of kMaxCapacity](https://searchfox.org/mozilla-central/rev/2f9eacd9d3d995c937b4251a5557d95d494c9be1/xpcom/string/nsTSubstring.cpp#35-39), the debugger tells me indeed that it's `2147483637`, which is "aprox. 2 GB". The rational behind this is probably to be safe against signed/unsigned conversions of 32Bit length values. The hard limit for [length would be `uint_32`](https://searchfox.org/mozilla-central/rev/2f9eacd9d3d995c937b4251a5557d95d494c9be1/xpcom/string/nsTStringRepr.h#94), it seems. I see two options here: 1) Define an own (lower) `const uint32_t kMaxFileAsDataURLLength = 2147400000;` and check it beforehand. This is probably safe, as it is very unlikely, that future modifications of `nsTSubstring` will reduce `kMaxCapacity` significantly or that `uint32_t` will ever have more/less than 32 bit (still a constant reads kind of bad here). 2) Add a factory function with error handling and use it here (and who knows where else). This is probably only a good idea, if we expect more places in our codebase where we could hit this limit through normal operations. If I try 1), I get an alert "Problem while reading ubuntu-19.10-desktop-amd64(1).iso (2463842304 bytes): NotReadableError", which is probably an improvable error message for this case, but the crash goes away.
Bug 847347 Comment 14 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
(In reply to Jens Stutte [:jstutte] (REO for FF 81) from comment #12) > This would indicate that files of size < aprox. 2 GB can work (if we have enough memory) So looking at the [value of kMaxCapacity](https://searchfox.org/mozilla-central/rev/2f9eacd9d3d995c937b4251a5557d95d494c9be1/xpcom/string/nsTSubstring.cpp#35-39), the debugger tells me indeed that it's `2147483637`, which is "aprox. 2 GB". The rationale behind this is probably to be safe against signed/unsigned conversions of 32Bit length values. The hard limit for [length would be `uint_32`](https://searchfox.org/mozilla-central/rev/2f9eacd9d3d995c937b4251a5557d95d494c9be1/xpcom/string/nsTStringRepr.h#94), it seems. I see two options here: 1) Define an own (lower) `const uint32_t kMaxFileAsDataURLLength = 2147400000;` and check it beforehand. This is probably safe, as it is very unlikely, that future modifications of `nsTSubstring` will reduce `kMaxCapacity` significantly or that `uint32_t` will ever have more/less than 32 bit (still a constant reads kind of bad here). 2) Add a factory function with error handling and use it here (and who knows where else). This is probably only a good idea, if we expect more places in our codebase where we could hit this limit through normal operations. If I try 1), I get an alert "Problem while reading ubuntu-19.10-desktop-amd64(1).iso (2463842304 bytes): NotReadableError", which is probably an improvable error message for this case, but the crash goes away.