Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bridge: re-introduce the max_read_size limit #21556

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cockpit/channels/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ class FsReadChannel(GeneratorChannel):

def do_yield_data(self, options: JsonObject) -> Generator[bytes, None, JsonObject]:
path = get_str(options, 'path')
max_read_size = get_int(options, 'max_read_size', None)
max_read_size = get_int(options, 'max_read_size', 16 * 1024 * 1024)

logger.debug('Opening file "%s" for reading', path)

try:
with open(path, 'rb') as filep:
buf = os.stat(filep.fileno())
if max_read_size is not None and buf.st_size > max_read_size:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, did the C bridge support any way of saying "indefinite"? Like "-1"? For download in files we have no way of limiting. But if we change files now to give -1, it will fail with the old bridge. So I think for the time being the only thing files can do is to set it to MAXINT64 for the time being. Then we add support for -1 here, and at some point we can change files accordingly. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C bridge never did, we never had big download support until cockpit-files and as files started with only supporting the Python bridge this just "worked".

Cockpit only had:

pkg/sosreport/sosreport.jsx:        max_read_size: 150 * 1024 * 1024,

Your proposal sounds good, it actually would unbreak our RHEL-8 testing was what I was thinking but it doesn't as we beiboot :-)

if buf.st_size > max_read_size:
raise ChannelError('too-large')

if self.is_binary and stat.S_ISREG(buf.st_mode):
Expand Down
8 changes: 7 additions & 1 deletion test/pytest/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ async def test_internal_metrics(transport: MockTransport) -> None:


@pytest.mark.asyncio
async def test_fsread1_errors(transport: MockTransport) -> None:
async def test_fsread1_errors(transport: MockTransport, tmp_path: Path) -> None:
await transport.check_open('fsread1', path='/etc/shadow', problem='access-denied')
await transport.check_open('fsread1', path='/', problem='internal-error',
reply_keys={'message': "[Errno 21] Is a directory: '/'"})
Expand All @@ -425,6 +425,12 @@ async def test_fsread1_errors(transport: MockTransport) -> None:
reply_keys={'message': "attribute 'max_read_size': must have type int"})
await transport.check_open('fsread1', path='/etc/passwd', max_read_size=1,
problem='too-large')
# default read size limit
big_file = tmp_path / 'bigfile.img'
fd = os.open(big_file, os.O_RDWR | os.O_CREAT)
os.posix_fallocate(fd, 0, 17 * 1024 * 1024)
await transport.check_open('fsread1', path=str(big_file),
problem='too-large')


@pytest.mark.asyncio
Expand Down
Loading