Open Bug 1783704 Opened 2 years ago Updated 2 years ago

`NetUtil.readInputStreamToString` doesn't handle short reads if charset is specified

Categories

(Core :: XPCOM, defect)

defect

Tracking

()

People

(Reporter: nika, Unassigned)

References

(Blocks 1 open bug)

Details

In bug 1170668, we fixed some issues with the nsIUnicharInputStream not handling short reads correctly internally, but it appears that some callers also don't handle short reads properly. The NetUtil.readInputStreamToString method doesn't correctly handle short reads if the charset argument is set, as readString() will not guarantee that aCount bytes of the original stream were successfully read. This would only happen if the internal read call used to fill the conversion stream's internal buffer successfully read exactly aCount bytes (due to it being the size of the internal buffer) which is not guaranteed.

We may need to introduce new APIs to handle this situation correctly, as there's no way to know how many output decoded characters correspond to aCount bytes of the input stream. Perhaps wrapping the provided stream into a length-limited input stream wrapper first and then reading until EOF would be a solution.

Severity: -- → S3
You need to log in before you can comment on or make changes to this bug.