From bec01778d9e7450a88fbcfe2766df280610c33c4 Mon Sep 17 00:00:00 2001
From: Robert Loehning <robert.loehning@nokia.com>
Date: Mon, 8 Mar 2010 20:19:33 +0100
Subject: [PATCH] Fixed crash when trying to copy large binary file

Reviewed-by: Oswald Buddenhagen
Task-number: QTCREATORBUG-484
---
 src/plugins/bineditor/bineditor.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/plugins/bineditor/bineditor.cpp b/src/plugins/bineditor/bineditor.cpp
index fbd2bb43be2..ec33a8889e9 100644
--- a/src/plugins/bineditor/bineditor.cpp
+++ b/src/plugins/bineditor/bineditor.cpp
@@ -41,6 +41,7 @@
 #include <QtGui/QClipboard>
 #include <QtGui/QFontMetrics>
 #include <QtGui/QMenu>
+#include <QtGui/QMessageBox>
 #include <QtGui/QPainter>
 #include <QtGui/QScrollBar>
 #include <QtGui/QWheelEvent>
@@ -1124,7 +1125,13 @@ void BinEditor::copy(bool raw)
     const int selStart = selectionStart();
     const int selEnd = selectionEnd();
     if (selStart < selEnd) {
-        const QByteArray &data = dataMid(selStart, selEnd - selStart);
+        const int selectionLength = selEnd - selStart;
+        if (selectionLength >> 22) {
+            QMessageBox::warning(this, tr("Copying Failed"),
+                                 tr("You cannot copy more than 4 MB of binary data."));
+            return;
+        }
+        const QByteArray &data = dataMid(selStart, selectionLength);
         if (raw) {
             QApplication::clipboard()->setText(data);
             return;
-- 
GitLab