Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-dev] small bug in UTF-8 BOM skip

Hi,

Just by chance, I happened to spot some buggy code in FileDocumentProvider:

https://github.com/eclipse-platform/eclipse.platform.ui/blob/master/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/FileDocumentProvider.java#L389

int n= 0;
do {
    int bytes= contentStream.read(new byte[IContentDescription.BOM_UTF_8.length]);
    if (bytes == -1)
        throw new IOException();
    n += bytes;
} while (n < IContentDescription.BOM_UTF_8.length);

The array length should be IContentDescription.BOM_UTF_8.length - n - otherwise this could read more bytes than intended.

It's probably never happened in practice, because nobody uses UTF-8 BOM and because in practice filestream.read doesn't return less bytes than requested except at the end of the file.

Note: Although Github issues seem to be the proper way to report issues in this component, Github has decided I shouldn't be allowed to raise Github issues without linking my phone number.


Back to the top