aboutsummaryrefslogtreecommitdiffstats
path: root/common/rfb
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2020-05-20 15:50:11 +0200
committerPierre Ossman <ossman@cendio.se>2020-05-21 11:40:57 +0200
commitb00d2fe17e686527ff66856a747438dbfc73c967 (patch)
tree9bb955301fc641f6355bc24b6943d50764f57fbf /common/rfb
parentd6bd230991495ad3bf97c2be764fbc034df51d9a (diff)
downloadtigervnc-b00d2fe17e686527ff66856a747438dbfc73c967.tar.gz
tigervnc-b00d2fe17e686527ff66856a747438dbfc73c967.zip
Make direct stream API a bit safer
Provide some safety checks when directly accessing the underlying pointer of streams.
Diffstat (limited to 'common/rfb')
-rw-r--r--common/rfb/JpegCompressor.cxx14
1 files changed, 7 insertions, 7 deletions
diff --git a/common/rfb/JpegCompressor.cxx b/common/rfb/JpegCompressor.cxx
index 5cc3855d..64c6d3f0 100644
--- a/common/rfb/JpegCompressor.cxx
+++ b/common/rfb/JpegCompressor.cxx
@@ -75,6 +75,7 @@ JpegOutputMessage(j_common_ptr cinfo)
struct JPEG_DEST_MGR {
struct jpeg_destination_mgr pub;
JpegCompressor *instance;
+ size_t chunkSize;
};
static void
@@ -84,8 +85,8 @@ JpegInitDestination(j_compress_ptr cinfo)
JpegCompressor *jc = dest->instance;
jc->clear();
- dest->pub.next_output_byte = jc->getptr();
- dest->pub.free_in_buffer = jc->avail();
+ dest->pub.next_output_byte = jc->getptr(jc->length());
+ dest->pub.free_in_buffer = dest->chunkSize = jc->avail();
}
static boolean
@@ -94,10 +95,9 @@ JpegEmptyOutputBuffer(j_compress_ptr cinfo)
JPEG_DEST_MGR *dest = (JPEG_DEST_MGR *)cinfo->dest;
JpegCompressor *jc = dest->instance;
- jc->setptr(jc->getend());
- jc->check(jc->length());
- dest->pub.next_output_byte = jc->getptr();
- dest->pub.free_in_buffer = jc->avail();
+ jc->setptr(jc->avail());
+ dest->pub.next_output_byte = jc->getptr(jc->length());
+ dest->pub.free_in_buffer = dest->chunkSize = jc->avail();
return TRUE;
}
@@ -108,7 +108,7 @@ JpegTermDestination(j_compress_ptr cinfo)
JPEG_DEST_MGR *dest = (JPEG_DEST_MGR *)cinfo->dest;
JpegCompressor *jc = dest->instance;
- jc->setptr(dest->pub.next_output_byte);
+ jc->setptr(dest->chunkSize - dest->pub.free_in_buffer);
}
JpegCompressor::JpegCompressor(int bufferLen) : MemOutStream(bufferLen)