Add an extra sanity check to Tracker's automatic text clipping extraction when
drag and dropping text files: before it would blindly read the entirety of the file's text contents regardless of size, which probably led to more than a few nasty surprises when someone attempted to drag very large (i.e. multimegabyte) text files. We now clamp the amount of data we read to 64KB. Though it's debatable if this feature is at all useful, since it may potentially be better implemented by handling entry_refs in dropped messages in BTextView directly (assuming a compatible type). Opinions welcome. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35715 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
a17770f44a
commit
ddee094350
@ -103,6 +103,7 @@ const float kCountViewWidth = 76;
|
||||
const uint32 kAddNewPoses = 'Tanp';
|
||||
const uint32 kAddPosesCompleted = 'Tapc';
|
||||
const int32 kMaxAddPosesChunk = 50;
|
||||
const uint32 kMaxTextClippingSize = 64 * 1024;
|
||||
|
||||
namespace BPrivate {
|
||||
extern bool delete_point(void *);
|
||||
@ -6736,6 +6737,9 @@ BPoseView::DragSelectedPoses(const BPose *pose, BPoint clickPoint)
|
||||
off_t size = 0;
|
||||
file.GetSize(&size);
|
||||
if (size) {
|
||||
// clamp the amount of text we extract in order to avoid very unpleasant surprises if, say, the user
|
||||
// happens to have a 100MB plain text file they want to drag around.
|
||||
size = min(size, (off_t)kMaxTextClippingSize);
|
||||
char *buffer = new char[size];
|
||||
if (file.Read(buffer, (size_t)size) == size) {
|
||||
message.AddData(kPlainTextMimeType, B_MIME_TYPE, buffer, (ssize_t)size);
|
||||
@ -6758,7 +6762,7 @@ BPoseView::DragSelectedPoses(const BPose *pose, BPoint clickPoint)
|
||||
delete [] buffer;
|
||||
}
|
||||
} else if (strcasecmp(type, kBitmapMimeType) == 0
|
||||
// got a text file
|
||||
// got a raw bitmap clipping file
|
||||
&& file.ReadAttr(kAttrClippingFile, B_RAW_TYPE, 0,
|
||||
&tmp, sizeof(int32)) == sizeof(int32)) {
|
||||
file.Seek(0, SEEK_SET);
|
||||
|
Loading…
Reference in New Issue
Block a user