Details
-
Bug
-
Resolution: Unresolved
-
Major
-
2.2.19.Final
-
None
Description
UndertowOutputStream has a method:
void transferFrom(FileChannel source) throws IOException
There's not obviously a contract documented for this, but the implementation reads:
long position = source.position(); long size = source.size(); Channels.transferBlocking(channel, source, position, size); updateWritten(size - position);
I believe that this is incorrect because transferBlocking is specified to transfer size bytes, but here size is the length of the file, rather than the size - position expected. Effectively, this method will only do the right thing if source.position() == 0.
I expect that the signature of the method should be:
void transferFrom(FileChannel source, long position, long size);
and the current method should do one of:
- be made to throw if source.position() != 0.
- simply write from position 0 each time. Now the position() of the channel is ignored, but it was useless if nonzero anyway.
- call Channels.transferBlocking(channel, source, position, size - position)
My preference would be for the second one since it'd be unexpected to have a signature that writes the 'rest' of the file, but a 'whole file' signature seems reasonable.
I don't know what the right solution here is, fwiw, and I'm not 100% sure there's even a bug - I rarely interact with nio primitives directly (I'm an InputStream kind of guy!) - but it seemed dodgy enough to report!