Skip to content

Possible invalid array access #5

@paulholder

Description

@paulholder

In the code

    public int getByte() throws IOException {
	if (bufferOffset >= bytesInBuffer) {
	    fillBuffer();
	}
	return buffer[bufferOffset++] & 0xff;
    }

the call to fillBuffer()

    private void fillBuffer() throws IOException {
	if (length == 0) {
	    throw (new IOException());
	}
	int cnt = 4096;
	if (cnt > length) {
	    cnt = length;
	}
	bytesInBuffer = istream.read(buffer, 0, cnt);
	if (bytesInBuffer == -1) {
	    throw (new IOException());
	}
	length -= bytesInBuffer;
	bufferOffset = 0;
    }

could potentially return having read less than a full buffer (in the case of network congestion or othewise). In particular the line bytesInBuffer = istream.read(buffer, 0, cnt); is not guaranteed to get all cnt bytes it wants.

It would then be possible that the reference to buffer[bufferOffset++] would not contain valid data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions