static int clipboard_delayed_size;
static bool clip_disabled;
+#define CLIP_SIZE_LIMIT 10000000
+#define CLIP_SIZE_LIMIT_INIT 30000
+
static void debugwrite (TrapContext *ctx, const TCHAR *name, uaecptr p, int size)
{
FILE *f;
xfree(txt);
}
-static void to_iff_ilbm(TrapContext *ctx, HBITMAP hbmp)
+static void to_iff_ilbm(TrapContext *ctx, HBITMAP hbmp, bool initial)
{
BITMAP bmp;
int bmpw, w, h, bpp, iffbpp, tsize, size, x, y, i;
if (!GetObject (hbmp, sizeof bmp, &bmp))
return;
+
w = bmp.bmWidth;
h = bmp.bmHeight;
bpp = bmp.bmBitsPixel;
return;
bmpw = (w * bpp / 8 + 3) & ~3;
size = bmpw * h;
+
+ if (size > (initial ? CLIP_SIZE_LIMIT_INIT : CLIP_SIZE_LIMIT)) {
+ if (clipboard_log) {
+ write_log(_T("clipboard: initial size too large, ignored.\n"));
+ }
+ return;
+ }
+
bmp.bmBits = xmalloc (uae_u8, size);
if (!GetBitmapBits (hbmp, size, bmp.bmBits)) {
xfree (bmp.bmBits);
clip_disabled = disabled;
}
-static void clipboard_read(TrapContext *ctx, HWND hwnd, bool keyboardinject)
+static void clipboard_read(TrapContext *ctx, HWND hwnd, bool keyboardinject, bool initial)
{
HGLOBAL hglb;
UINT f;
if (hglb != NULL) {
TCHAR *lptstr = (TCHAR*)GlobalLock (hglb);
if (lptstr != NULL) {
- if (clipboard_log) {
- write_log (_T("clipboard: CF_UNICODETEXT '%s'\n"), lptstr);
- }
- if (keyboardinject) {
- to_keyboard(lptstr);
+ size_t len = _tcslen(lptstr);
+ if (len > (initial ? CLIP_SIZE_LIMIT_INIT : CLIP_SIZE_LIMIT)) {
+ if (clipboard_log) {
+ write_log(_T("clipboard: initial size too large, ignored.\n"));
+ }
} else {
- to_iff_text(ctx, lptstr);
+ if (clipboard_log) {
+ write_log (_T("clipboard: CF_UNICODETEXT '%s'\n"), lptstr);
+ }
+ if (keyboardinject) {
+ to_keyboard(lptstr);
+ } else {
+ to_iff_text(ctx, lptstr);
+ }
}
GlobalUnlock (hglb);
}
if (clipboard_log) {
write_log (_T("clipboard: CF_BITMAP\n"));
}
- to_iff_ilbm(ctx, hbmp);
+ to_iff_ilbm(ctx, hbmp, initial);
}
}
CloseClipboard ();
clipboard_change = 1;
return;
}
- clipboard_read(NULL, hwnd, false);
+ clipboard_read(NULL, hwnd, false, false);
}
static int clipboard_put_bmp_real (HBITMAP hbmp)
signaling = 0;
write_log (_T("clipboard initialized\n"));
initialized = 1;
- clipboard_read(ctx, chwnd, false);
+ clipboard_read(ctx, chwnd, false, true);
}
void amiga_clipboard_task_start(TrapContext *ctx, uaecptr data)
if (!initialized || !hwnd)
return;
if (clipactive && clipboard_change) {
- clipboard_read(NULL, hwnd, false);
+ clipboard_read(NULL, hwnd, false, false);
}
if (!clipactive && clipboard_delayed_data) {
if (clipboard_delayed_size < 0) {
void target_paste_to_keyboard(void)
{
- clipboard_read(NULL, chwnd, true);
+ clipboard_read(NULL, chwnd, true, false);
}
// force 2 second delay before accepting new data