Skip to content

Commit

Permalink
Issue #12695 - reject attempts to memory map files from FileSystems t…
Browse files Browse the repository at this point in the history
…hat do not support it.
  • Loading branch information
joakime committed Jan 9, 2025
1 parent 308cdf4 commit d1a8929
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ private SingleBufferFileMappedHttpContent(HttpContent content) throws IOExceptio
if (path == null)
throw new IOException("Cannot memory map Content whose Resource is not backed by a Path: " + content.getResource());
_buffer = BufferUtil.toMappedBuffer(path);
if (_buffer == null)
throw new IOException("Cannot memory map Content (not supported by underlying FileSystem): " + content.getResource());
_contentLength = new HttpField(HttpHeader.CONTENT_LENGTH, Integer.toString(_buffer.remaining()));
_lastModified = content.getLastModified();
_lastModifiedInstant = content.getLastModifiedInstant();
Expand Down Expand Up @@ -176,6 +178,8 @@ private MultiBufferFileMappedHttpContent(HttpContent content, int maxBufferSize)
{
long len = Math.min(contentLength - currentPos, maxBufferSize);
_buffers[i] = BufferUtil.toMappedBuffer(path, currentPos, len);
if (_buffers[i] == null)
throw new IOException("Cannot memory map Content (not supported by underlying FileSystem): " + content.getResource());
currentPos += len;
total += _buffers[i].remaining();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ protected Action process() throws Exception
long len = Math.min(MAX_MAPPED_BUFFER_SIZE, fileLength - _pos);
_last = (_pos + len == fileLength);
ByteBuffer buffer = BufferUtil.toMappedBuffer(_filePath, _pos, len);
if (buffer == null)
throw new IOException("Cannot memory map file (not supported by underlying FileSystem): " + _filePath.toUri());
getNextInterceptor().write(buffer, _last, this);
_pos += len;
return Action.SCHEDULED;
Expand Down

0 comments on commit d1a8929

Please sign in to comment.