From ebdedf9bbf6903e787c78c96a23a73908f361cf0 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Wed, 16 Jan 2008 08:27:11 +0000 Subject: [PATCH] disallow importing/exporting big pictures, since the Link* api doesn't allow sending more than 64 kb through it. At least printing via ShowImage doesn't hang the app anymore git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23554 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/ServerPicture.cpp | 54 ++++++++++++++++++------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/servers/app/ServerPicture.cpp b/src/servers/app/ServerPicture.cpp index 51d1acd2ef..cc0bb791d5 100644 --- a/src/servers/app/ServerPicture.cpp +++ b/src/servers/app/ServerPicture.cpp @@ -965,23 +965,24 @@ ServerPicture::ImportData(BPrivate::LinkReceiver &link) int32 size = 0; link.Read(&size); + if (size >= 65536) { + //TODO: Pass via an area. + // Ideally the Link** api would allow to write partial messages, + // so that a big picture could be written in chunks of 4096 bytes + // or so + return B_ERROR; + } + off_t oldPosition = fData->Position(); fData->Seek(0, SEEK_SET); - ssize_t toWrite = size; - // TODO: For some reason, this doesn't work. Bug in LinkReceiver ? - /*char buffer[BUFFER_SIZE]; - while (toWrite > 0) { - ssize_t read = link.Read(buffer, toWrite > BUFFER_SIZE ? BUFFER_SIZE : toWrite); - if (read < B_OK) - return (status_t)read; - fData->Write(buffer, read); - toWrite -= read; - }*/ - - char buffer[toWrite]; - link.Read(buffer, toWrite); - fData->Write(buffer, toWrite); + // TODO: Oh yeah... 65kb on the stack... + char buffer[size]; + status_t read = link.Read(buffer, size); + if (read < B_OK) + return (status_t)read; + + fData->Write(buffer, size); fData->Seek(oldPosition, SEEK_SET); @@ -1011,16 +1012,23 @@ ServerPicture::ExportData(BPrivate::PortLink &link) off_t size = 0; fData->GetSize(&size); link.Attach((int32)size); - - ssize_t toWrite = size; - char buffer[BUFFER_SIZE]; - while (toWrite > 0) { - ssize_t read = fData->Read(buffer, toWrite > BUFFER_SIZE ? BUFFER_SIZE : toWrite); - if (read < B_OK) - return (status_t)read; - link.Attach(buffer, read); - toWrite -= read; + if (size >= 65536) { + //TODO: Pass via an area + link.CancelMessage(); + link.StartMessage(B_ERROR); + return B_ERROR; } + // TODO: Oh yeah... 65kb on the stack... + char buffer[size]; + ssize_t read = fData->Read(buffer, size); + if (read < B_OK) + return (status_t)read; + if (link.Attach(buffer, read) < B_OK) { + // + link.CancelMessage(); + link.StartMessage(B_ERROR); + }; + fData->Seek(oldPosition, SEEK_SET);