sahvx655-wq created FELIX-6841:
----------------------------------
Summary: Fix ArrayIndexOutOfBoundsException in Pipe.isTty
Key: FELIX-6841
URL: https://issues.apache.org/jira/browse/FELIX-6841
Project: Felix
Issue Type: Bug
Components: Gogo Runtime
Reporter: sahvx655-wq
An {{ArrayIndexOutOfBoundsException}} occurs in {{Pipe.isTty(int fd)}} when the
file descriptor index {{fd}} is equal to or greater than the {{streams}} array
length.
In {{{}Pipe.java{}}}:
{{public boolean isTty(int fd) \{
// TODO: this assumes that the session is always created with input/output
tty streams
if (fd < 0 || fd > streams.length) {
return false;
}
return streams[fd] != null && !toclose[fd];
}}}
The boundary check uses {{fd > streams.length}} instead of {{{}fd >=
streams.length{}}}.
Since Java arrays are zero-indexed, an index equal to {{streams.length}} is
already out of bounds. When {{{}fd == streams.length{}}}, the bounds check
passes and the method attempts to access {{{}streams[fd]{}}}, resulting in an
{{{}ArrayIndexOutOfBoundsException{}}}.
Update the boundary check to use {{fd >= streams.length}} so that invalid file
descriptor indices are rejected before accessing the array.
This ensures that {{isTty()}} safely returns {{false}} for out-of-bounds
descriptors instead of throwing an exception.
Verification
* Add a test case covering out-of-bounds file descriptor values.
* Verify that {{isTty()}} returns {{false}} when {{{}fd >= streams.length{}}}.
* Confirm that no {{ArrayIndexOutOfBoundsException}} is thrown.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)