diff options
Diffstat (limited to 'java/com/tigervnc/rfb/CMsgReader.java')
-rw-r--r-- | java/com/tigervnc/rfb/CMsgReader.java | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/java/com/tigervnc/rfb/CMsgReader.java b/java/com/tigervnc/rfb/CMsgReader.java index e65db8c6..56b761e4 100644 --- a/java/com/tigervnc/rfb/CMsgReader.java +++ b/java/com/tigervnc/rfb/CMsgReader.java @@ -1,5 +1,5 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * Copyright (C) 2011-2017 Brian P. Hinz + * Copyright (C) 2011-2019 Brian P. Hinz * Copyright (C) 2017 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify @@ -34,27 +34,26 @@ import com.tigervnc.rdr.*; public class CMsgReader { + static LogWriter vlog = new LogWriter("CMsgReader"); + protected CMsgReader(CMsgHandler handler_, InStream is_) { imageBufIdealSize = 0; handler = handler_; is = is_; + nUpdateRectsLeft = 0; imageBuf = null; imageBufSize = 0; - nUpdateRectsLeft = 0; } public void readServerInit() { int width = is.readU16(); int height = is.readU16(); - handler.setDesktopSize(width, height); PixelFormat pf = new PixelFormat(); pf.read(is); - handler.setPixelFormat(pf); String name = is.readString(); - handler.setName(name); - handler.serverInit(); + handler.serverInit(width, height, pf, name); } public void readMsg() @@ -82,6 +81,7 @@ public class CMsgReader { readEndOfContinuousUpdates(); break; default: + vlog.error("unknown message type "+type); throw new Exception("unknown message type"); } } else { @@ -148,11 +148,13 @@ public class CMsgReader { { is.skip(3); int len = is.readU32(); + if (len > 256*1024) { is.skip(len); vlog.error("cut text too long ("+len+" bytes) - ignoring"); return; } + ByteBuffer buf = ByteBuffer.allocate(len); is.readBytes(buf, len); Charset latin1 = Charset.forName("ISO-8859-1"); @@ -196,10 +198,10 @@ public class CMsgReader { protected void readRect(Rect r, int encoding) { - if ((r.br.x > handler.cp.width) || (r.br.y > handler.cp.height)) { + if ((r.br.x > handler.server.width()) || (r.br.y > handler.server.height())) { vlog.error("Rect too big: "+r.width()+"x"+r.height()+" at "+ - r.tl.x+","+r.tl.y+" exceeds "+handler.cp.width+"x"+ - handler.cp.height); + r.tl.x+","+r.tl.y+" exceeds "+handler.server.width()+"x"+ + handler.server.height()); throw new Exception("Rect too big"); } @@ -268,7 +270,7 @@ public class CMsgReader { protected void readSetCursor(int width, int height, Point hotspot) { - int data_len = width * height * (handler.cp.pf().bpp/8); + int data_len = width * height * (handler.server.pf().bpp/8); int mask_len = ((width+7)/8) * height; ByteBuffer data = ByteBuffer.allocate(data_len); ByteBuffer mask = ByteBuffer.allocate(mask_len); @@ -295,9 +297,9 @@ public class CMsgReader { else out.put((byte)0); - handler.cp.pf().rgbFromBuffer(out.duplicate(), in.duplicate(), 1); + handler.server.pf().rgbFromBuffer(out.duplicate(), in.duplicate(), 1); - in.position(in.position() + handler.cp.pf().bpp/8); + in.position(in.position() + handler.server.pf().bpp/8); out.position(out.position() + 3); } } @@ -320,10 +322,10 @@ public class CMsgReader { encoding = is.readS32(); - origPF = handler.cp.pf(); - handler.cp.setPF(rgbaPF); + origPF = handler.server.pf(); + handler.server.setPF(rgbaPF); handler.readAndDecodeRect(pb.getRect(), encoding, pb); - handler.cp.setPF(origPF); + handler.server.setPF(origPF); // ARGB with pre-multiplied alpha works best for BufferedImage if (pb.area() > 0) { @@ -412,7 +414,7 @@ public class CMsgReader { imageBuf = new int[imageBufSize]; } if (nPixels != 0) - nPixels = imageBufSize / (handler.cp.pf().bpp / 8); + nPixels = imageBufSize / (handler.server.pf().bpp / 8); return imageBuf; } @@ -425,6 +427,4 @@ public class CMsgReader { protected int nUpdateRectsLeft; protected int[] imageBuf; protected int imageBufSize; - - static LogWriter vlog = new LogWriter("CMsgReader"); } |