diff --git a/channels/audin/client/audin_main.c b/channels/audin/client/audin_main.c index 50c8f1387..bf409e043 100644 --- a/channels/audin/client/audin_main.c +++ b/channels/audin/client/audin_main.c @@ -175,7 +175,7 @@ static int audin_process_formats(IWTSVirtualChannelCallback* pChannelCallback, w /* Store the agreed format in the corresponding index */ callback->formats[callback->formats_count++] = format; /* Put the format to output buffer */ - stream_check_size(out, 18 + format.cbSize); + Stream_EnsureRemainingCapacity(out, 18 + format.cbSize); stream_write(out, fm, 18 + format.cbSize); } } diff --git a/channels/audin/server/audin.c b/channels/audin/server/audin.c index c5d00bc9d..88b8e8f77 100644 --- a/channels/audin/server/audin.c +++ b/channels/audin/server/audin.c @@ -111,7 +111,9 @@ static void audin_server_send_formats(audin_server* audin, wStream* s) nAvgBytesPerSec = audin->context.server_formats[i].nSamplesPerSec * audin->context.server_formats[i].nChannels * audin->context.server_formats[i].wBitsPerSample / 8; - stream_check_size(s, 18); + + Stream_EnsureRemainingCapacity(s, 18); + stream_write_UINT16(s, audin->context.server_formats[i].wFormatTag); stream_write_UINT16(s, audin->context.server_formats[i].nChannels); stream_write_UINT32(s, audin->context.server_formats[i].nSamplesPerSec); @@ -119,9 +121,10 @@ static void audin_server_send_formats(audin_server* audin, wStream* s) stream_write_UINT16(s, audin->context.server_formats[i].nBlockAlign); stream_write_UINT16(s, audin->context.server_formats[i].wBitsPerSample); stream_write_UINT16(s, audin->context.server_formats[i].cbSize); + if (audin->context.server_formats[i].cbSize) { - stream_check_size(s, audin->context.server_formats[i].cbSize); + Stream_EnsureRemainingCapacity(s, audin->context.server_formats[i].cbSize); stream_write(s, audin->context.server_formats[i].data, audin->context.server_formats[i].cbSize); } @@ -333,7 +336,7 @@ static void* audin_server_thread_func(void* arg) if (bytes_returned == 0) break; - stream_check_size(s, (int) bytes_returned); + Stream_EnsureRemainingCapacity(s, (int) bytes_returned); if (WTSVirtualChannelRead(audin->audin_channel, 0, stream_get_head(s), Stream_Capacity(s), &bytes_returned) == FALSE) diff --git a/channels/cliprdr/client/cliprdr_format.c b/channels/cliprdr/client/cliprdr_format.c index 373c2abcd..4fa404675 100644 --- a/channels/cliprdr/client/cliprdr_format.c +++ b/channels/cliprdr/client/cliprdr_format.c @@ -87,7 +87,7 @@ void cliprdr_process_format_list_event(cliprdrPlugin* cliprdr, RDP_CB_FORMAT_LIS if (!cliprdr->use_long_format_names) name_length = 32; - stream_extend(body, Stream_Capacity(body) + 4 + name_length); + Stream_EnsureRemainingCapacity(body, Stream_Capacity(body) + 4 + name_length); stream_write_UINT32(body, cb_event->formats[i]); stream_write(body, name, name_length); diff --git a/channels/drive/client/drive_file.c b/channels/drive/client/drive_file.c index 8c1006eed..9d4f35195 100644 --- a/channels/drive/client/drive_file.c +++ b/channels/drive/client/drive_file.c @@ -391,7 +391,7 @@ BOOL drive_file_query_information(DRIVE_FILE* file, UINT32 FsInformationClass, w case FileBasicInformation: /* http://msdn.microsoft.com/en-us/library/cc232094.aspx */ stream_write_UINT32(output, 36); /* Length */ - stream_check_size(output, 36); + Stream_EnsureRemainingCapacity(output, 36); stream_write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* CreationTime */ stream_write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_atime)); /* LastAccessTime */ stream_write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* LastWriteTime */ @@ -403,7 +403,7 @@ BOOL drive_file_query_information(DRIVE_FILE* file, UINT32 FsInformationClass, w case FileStandardInformation: /* http://msdn.microsoft.com/en-us/library/cc232088.aspx */ stream_write_UINT32(output, 22); /* Length */ - stream_check_size(output, 22); + Stream_EnsureRemainingCapacity(output, 22); stream_write_UINT64(output, st.st_size); /* AllocationSize */ stream_write_UINT64(output, st.st_size); /* EndOfFile */ stream_write_UINT32(output, st.st_nlink); /* NumberOfLinks */ @@ -415,7 +415,7 @@ BOOL drive_file_query_information(DRIVE_FILE* file, UINT32 FsInformationClass, w case FileAttributeTagInformation: /* http://msdn.microsoft.com/en-us/library/cc232093.aspx */ stream_write_UINT32(output, 8); /* Length */ - stream_check_size(output, 8); + Stream_EnsureRemainingCapacity(output, 8); stream_write_UINT32(output, FILE_ATTR_SYSTEM_TO_RDP(file, st)); /* FileAttributes */ stream_write_UINT32(output, 0); /* ReparseTag */ break; @@ -616,7 +616,7 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT case FileDirectoryInformation: /* http://msdn.microsoft.com/en-us/library/cc232097.aspx */ stream_write_UINT32(output, 64 + length); /* Length */ - stream_check_size(output, 64 + length); + Stream_EnsureRemainingCapacity(output, 64 + length); stream_write_UINT32(output, 0); /* NextEntryOffset */ stream_write_UINT32(output, 0); /* FileIndex */ stream_write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* CreationTime */ @@ -633,7 +633,7 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT case FileFullDirectoryInformation: /* http://msdn.microsoft.com/en-us/library/cc232068.aspx */ stream_write_UINT32(output, 68 + length); /* Length */ - stream_check_size(output, 68 + length); + Stream_EnsureRemainingCapacity(output, 68 + length); stream_write_UINT32(output, 0); /* NextEntryOffset */ stream_write_UINT32(output, 0); /* FileIndex */ stream_write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* CreationTime */ @@ -651,7 +651,7 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT case FileBothDirectoryInformation: /* http://msdn.microsoft.com/en-us/library/cc232095.aspx */ stream_write_UINT32(output, 93 + length); /* Length */ - stream_check_size(output, 93 + length); + Stream_EnsureRemainingCapacity(output, 93 + length); stream_write_UINT32(output, 0); /* NextEntryOffset */ stream_write_UINT32(output, 0); /* FileIndex */ stream_write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* CreationTime */ @@ -672,7 +672,7 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT case FileNamesInformation: /* http://msdn.microsoft.com/en-us/library/cc232077.aspx */ stream_write_UINT32(output, 12 + length); /* Length */ - stream_check_size(output, 12 + length); + Stream_EnsureRemainingCapacity(output, 12 + length); stream_write_UINT32(output, 0); /* NextEntryOffset */ stream_write_UINT32(output, 0); /* FileIndex */ stream_write_UINT32(output, length); /* FileNameLength */ diff --git a/channels/drive/client/drive_main.c b/channels/drive/client/drive_main.c index 015e1f125..1c728543a 100644 --- a/channels/drive/client/drive_main.c +++ b/channels/drive/client/drive_main.c @@ -267,7 +267,7 @@ static void drive_process_irp_read(DRIVE_DEVICE* disk, IRP* irp) if (Length > 0) { - stream_check_size(irp->output, (int) Length); + Stream_EnsureRemainingCapacity(irp->output, (int) Length); stream_write(irp->output, buffer, Length); } @@ -405,7 +405,7 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* disk, IRP* /* http://msdn.microsoft.com/en-us/library/cc232108.aspx */ length = ConvertToUnicode(CP_UTF8, 0, volumeLabel, -1, &outStr, 0) * 2; stream_write_UINT32(output, 17 + length); /* Length */ - stream_check_size(output, 17 + length); + Stream_EnsureRemainingCapacity(output, 17 + length); stream_write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_ctime)); /* VolumeCreationTime */ #ifdef ANDROID stream_write_UINT32(output, svfst.f_fsid.__val[0]); /* VolumeSerialNumber */ @@ -422,7 +422,7 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* disk, IRP* case FileFsSizeInformation: /* http://msdn.microsoft.com/en-us/library/cc232107.aspx */ stream_write_UINT32(output, 24); /* Length */ - stream_check_size(output, 24); + Stream_EnsureRemainingCapacity(output, 24); stream_write_UINT64(output, svfst.f_blocks); /* TotalAllocationUnits */ stream_write_UINT64(output, svfst.f_bavail); /* AvailableAllocationUnits */ stream_write_UINT32(output, 1); /* SectorsPerAllocationUnit */ @@ -433,7 +433,7 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* disk, IRP* /* http://msdn.microsoft.com/en-us/library/cc232101.aspx */ length = ConvertToUnicode(CP_UTF8, 0, diskType, -1, &outStr, 0) * 2; stream_write_UINT32(output, 12 + length); /* Length */ - stream_check_size(output, 12 + length); + Stream_EnsureRemainingCapacity(output, 12 + length); stream_write_UINT32(output, FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES | @@ -451,7 +451,7 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* disk, IRP* case FileFsFullSizeInformation: /* http://msdn.microsoft.com/en-us/library/cc232104.aspx */ stream_write_UINT32(output, 32); /* Length */ - stream_check_size(output, 32); + Stream_EnsureRemainingCapacity(output, 32); stream_write_UINT64(output, svfst.f_blocks); /* TotalAllocationUnits */ stream_write_UINT64(output, svfst.f_bavail); /* CallerAvailableAllocationUnits */ stream_write_UINT64(output, svfst.f_bfree); /* AvailableAllocationUnits */ @@ -462,7 +462,7 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* disk, IRP* case FileFsDeviceInformation: /* http://msdn.microsoft.com/en-us/library/cc232109.aspx */ stream_write_UINT32(output, 8); /* Length */ - stream_check_size(output, 8); + Stream_EnsureRemainingCapacity(output, 8); stream_write_UINT32(output, FILE_DEVICE_DISK); /* DeviceType */ stream_write_UINT32(output, 0); /* Characteristics */ break; diff --git a/channels/parallel/client/parallel_main.c b/channels/parallel/client/parallel_main.c index f785475da..449c0f384 100644 --- a/channels/parallel/client/parallel_main.c +++ b/channels/parallel/client/parallel_main.c @@ -157,7 +157,7 @@ static void parallel_process_irp_read(PARALLEL_DEVICE* parallel, IRP* irp) if (Length > 0) { - stream_check_size(irp->output, Length); + Stream_EnsureRemainingCapacity(irp->output, Length); stream_write(irp->output, buffer, Length); } diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index 662aa0624..2efac7afa 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -176,7 +176,7 @@ static void rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr, BOOL use (device->type == RDPDR_DTYP_SMARTCARD) || user_loggedon) { data_len = (device->data == NULL ? 0 : Stream_GetPosition(device->data)); - stream_check_size(data_out, 20 + data_len); + Stream_EnsureRemainingCapacity(data_out, 20 + data_len); stream_write_UINT32(data_out, device->type); /* deviceType */ stream_write_UINT32(data_out, device->id); /* deviceID */ diff --git a/channels/rdpsnd/server/rdpsnd.c b/channels/rdpsnd/server/rdpsnd.c index 4c2f88caf..6beb25d77 100644 --- a/channels/rdpsnd/server/rdpsnd.c +++ b/channels/rdpsnd/server/rdpsnd.c @@ -224,7 +224,7 @@ static void* rdpsnd_server_thread_func(void* arg) if (bytes_returned == 0) break; - stream_check_size(s, (int) bytes_returned); + Stream_EnsureRemainingCapacity(s, (int) bytes_returned); if (WTSVirtualChannelRead(rdpsnd->rdpsnd_channel, 0, stream_get_head(s), Stream_Capacity(s), &bytes_returned) == FALSE) @@ -414,7 +414,7 @@ static BOOL rdpsnd_server_send_audio_pdu(rdpsnd_server* rdpsnd) Stream_SetPosition(s, 0); /* Wave PDU */ - stream_check_size(s, size + fill_size); + Stream_EnsureRemainingCapacity(s, size + fill_size); stream_write_UINT32(s, 0); /* bPad */ stream_write(s, src + 4, size - 4); diff --git a/channels/serial/client/serial_main.c b/channels/serial/client/serial_main.c index ec6e5abea..dd9848559 100644 --- a/channels/serial/client/serial_main.c +++ b/channels/serial/client/serial_main.c @@ -193,7 +193,7 @@ static void serial_process_irp_read(SERIAL_DEVICE* serial, IRP* irp) if (Length > 0) { - stream_check_size(irp->output, Length); + Stream_EnsureRemainingCapacity(irp->output, Length); stream_write(irp->output, buffer, Length); } diff --git a/channels/server/channels.c b/channels/server/channels.c index e7a41f912..ddea61d95 100644 --- a/channels/server/channels.c +++ b/channels/server/channels.c @@ -206,7 +206,7 @@ static void wts_read_drdynvc_data_first(rdpPeerChannel* channel, wStream* s, int return; Stream_SetPosition(channel->receive_data, 0); - stream_check_size(channel->receive_data, (int) channel->dvc_total_length); + Stream_EnsureRemainingCapacity(channel->receive_data, (int) channel->dvc_total_length); stream_write(channel->receive_data, Stream_Pointer(s), length); } @@ -356,7 +356,7 @@ static void wts_write_drdynvc_create_request(wStream *s, UINT32 ChannelId, const wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId); len = strlen(ChannelName) + 1; - stream_check_size(s, (int) len); + Stream_EnsureRemainingCapacity(s, (int) len); stream_write(s, ChannelName, len); } @@ -367,7 +367,7 @@ static void WTSProcessChannelData(rdpPeerChannel* channel, int channelId, BYTE* Stream_SetPosition(channel->receive_data, 0); } - stream_check_size(channel->receive_data, size); + Stream_EnsureRemainingCapacity(channel->receive_data, size); stream_write(channel->receive_data, data, size); if (flags & CHANNEL_FLAG_LAST) diff --git a/channels/smartcard/client/smartcard_operations.c b/channels/smartcard/client/smartcard_operations.c index fe2603202..0c9fe71a6 100644 --- a/channels/smartcard/client/smartcard_operations.c +++ b/channels/smartcard/client/smartcard_operations.c @@ -1395,7 +1395,7 @@ void smartcard_device_control(SMARTCARD_DEVICE* scard, IRP* irp) // Stream_Seek(irp->input, 4); /* rpce len */ /* [MS-RDPESC] 3.2.5.1 Sending Outgoing Messages */ - stream_extend(irp->output, 2048); + Stream_EnsureRemainingCapacity(irp->output, 2048); irp_result_pos = Stream_GetPosition(irp->output); diff --git a/channels/tsmf/client/tsmf_ifman.c b/channels/tsmf/client/tsmf_ifman.c index aeee1c591..5de7dea13 100644 --- a/channels/tsmf/client/tsmf_ifman.c +++ b/channels/tsmf/client/tsmf_ifman.c @@ -44,7 +44,7 @@ int tsmf_ifman_rim_exchange_capability_request(TSMF_IFMAN* ifman) stream_read_UINT32(ifman->input, CapabilityValue); DEBUG_DVC("server CapabilityValue %d", CapabilityValue); - stream_check_size(ifman->output, 8); + Stream_EnsureRemainingCapacity(ifman->output, 8); stream_write_UINT32(ifman->output, 1); /* CapabilityValue */ stream_write_UINT32(ifman->output, 0); /* Result */ @@ -61,7 +61,7 @@ int tsmf_ifman_exchange_capability_request(TSMF_IFMAN* ifman) UINT32 numHostCapabilities; pos = Stream_GetPosition(ifman->output); - stream_check_size(ifman->output, ifman->input_size + 4); + Stream_EnsureRemainingCapacity(ifman->output, ifman->input_size + 4); stream_copy(ifman->output, ifman->input, ifman->input_size); Stream_SetPosition(ifman->output, pos); @@ -117,7 +117,7 @@ int tsmf_ifman_check_format_support_request(TSMF_IFMAN* ifman) if (FormatSupported) DEBUG_DVC("format ok."); - stream_check_size(ifman->output, 12); + Stream_EnsureRemainingCapacity(ifman->output, 12); stream_write_UINT32(ifman->output, FormatSupported); stream_write_UINT32(ifman->output, PlatformCookie); stream_write_UINT32(ifman->output, 0); /* Result */ @@ -191,7 +191,7 @@ int tsmf_ifman_set_topology_request(TSMF_IFMAN* ifman) { DEBUG_DVC(""); - stream_check_size(ifman->output, 8); + Stream_EnsureRemainingCapacity(ifman->output, 8); stream_write_UINT32(ifman->output, 1); /* TopologyReady */ stream_write_UINT32(ifman->output, 0); /* Result */ ifman->output_interface_id = TSMF_INTERFACE_DEFAULT | STREAM_ID_STUB; @@ -243,7 +243,7 @@ int tsmf_ifman_shutdown_presentation(TSMF_IFMAN* ifman) pexisted = 0; - stream_check_size(ifman->output, 4); + Stream_EnsureRemainingCapacity(ifman->output, 4); stream_write_UINT32(ifman->output, 0); /* Result */ ifman->output_interface_id = TSMF_INTERFACE_DEFAULT | STREAM_ID_STUB; @@ -489,7 +489,7 @@ int tsmf_ifman_on_end_of_stream(TSMF_IFMAN* ifman) } DEBUG_DVC("StreamId %d", StreamId); - stream_check_size(ifman->output, 16); + Stream_EnsureRemainingCapacity(ifman->output, 16); stream_write_UINT32(ifman->output, CLIENT_EVENT_NOTIFICATION); /* FunctionId */ stream_write_UINT32(ifman->output, StreamId); /* StreamId */ stream_write_UINT32(ifman->output, TSMM_CLIENT_EVENT_ENDOFSTREAM); /* EventId */ @@ -512,7 +512,7 @@ int tsmf_ifman_on_playback_started(TSMF_IFMAN* ifman) else DEBUG_WARN("unknown presentation id"); - stream_check_size(ifman->output, 16); + Stream_EnsureRemainingCapacity(ifman->output, 16); stream_write_UINT32(ifman->output, CLIENT_EVENT_NOTIFICATION); /* FunctionId */ stream_write_UINT32(ifman->output, 0); /* StreamId */ stream_write_UINT32(ifman->output, TSMM_CLIENT_EVENT_START_COMPLETED); /* EventId */ @@ -573,7 +573,7 @@ int tsmf_ifman_on_playback_stopped(TSMF_IFMAN* ifman) else DEBUG_WARN("unknown presentation id"); - stream_check_size(ifman->output, 16); + Stream_EnsureRemainingCapacity(ifman->output, 16); stream_write_UINT32(ifman->output, CLIENT_EVENT_NOTIFICATION); /* FunctionId */ stream_write_UINT32(ifman->output, 0); /* StreamId */ stream_write_UINT32(ifman->output, TSMM_CLIENT_EVENT_STOP_COMPLETED); /* EventId */ @@ -587,7 +587,7 @@ int tsmf_ifman_on_playback_rate_changed(TSMF_IFMAN * ifman) { DEBUG_DVC(""); - stream_check_size(ifman->output, 16); + Stream_EnsureRemainingCapacity(ifman->output, 16); stream_write_UINT32(ifman->output, CLIENT_EVENT_NOTIFICATION); /* FunctionId */ stream_write_UINT32(ifman->output, 0); /* StreamId */ stream_write_UINT32(ifman->output, TSMM_CLIENT_EVENT_MONITORCHANGED); /* EventId */ diff --git a/libfreerdp/codec/nsc_encode.c b/libfreerdp/codec/nsc_encode.c index 36c1988e9..d47fb6670 100644 --- a/libfreerdp/codec/nsc_encode.c +++ b/libfreerdp/codec/nsc_encode.c @@ -349,7 +349,7 @@ void nsc_compose_message(NSC_CONTEXT* context, wStream* s, PROFILER_EXIT(context->priv->prof_nsc_rle_compress_data); /* Assemble the NSCodec message into stream */ - stream_check_size(s, 20); + Stream_EnsureRemainingCapacity(s, 20); stream_write_UINT32(s, context->nsc_stream.PlaneByteCount[0]); /* LumaPlaneByteCount (4 bytes) */ stream_write_UINT32(s, context->nsc_stream.PlaneByteCount[1]); /* OrangeChromaPlaneByteCount (4 bytes) */ stream_write_UINT32(s, context->nsc_stream.PlaneByteCount[2]); /* GreenChromaPlaneByteCount (4 bytes) */ @@ -362,7 +362,7 @@ void nsc_compose_message(NSC_CONTEXT* context, wStream* s, { if (context->nsc_stream.PlaneByteCount[i] > 0) { - stream_check_size(s, (int) context->nsc_stream.PlaneByteCount[i]); + Stream_EnsureRemainingCapacity(s, (int) context->nsc_stream.PlaneByteCount[i]); stream_write(s, context->priv->plane_buf[i], context->nsc_stream.PlaneByteCount[i]); } } diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index cb9b4dcb4..9044ca563 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -942,7 +942,7 @@ static void rfx_compose_message_context(RFX_CONTEXT* context, wStream* s) void rfx_compose_message_header(RFX_CONTEXT* context, wStream* s) { - stream_check_size(s, 12 + 10 + 12 + 13); + Stream_EnsureRemainingCapacity(s, 12 + 10 + 12 + 13); rfx_compose_message_sync(context, s); rfx_compose_message_context(context, s); @@ -954,7 +954,7 @@ void rfx_compose_message_header(RFX_CONTEXT* context, wStream* s) static void rfx_compose_message_frame_begin(RFX_CONTEXT* context, wStream* s) { - stream_check_size(s, 14); + Stream_EnsureRemainingCapacity(s, 14); stream_write_UINT16(s, WBT_FRAME_BEGIN); /* CodecChannelT.blockType */ stream_write_UINT32(s, 14); /* CodecChannelT.blockLen */ @@ -973,7 +973,7 @@ static void rfx_compose_message_region(RFX_CONTEXT* context, wStream* s, int i; size = 15 + num_rects * 8; - stream_check_size(s, size); + Stream_EnsureRemainingCapacity(s, size); stream_write_UINT16(s, WBT_REGION); /* CodecChannelT.blockType */ stream_write_UINT32(s, size); /* set CodecChannelT.blockLen later */ @@ -1004,7 +1004,7 @@ static void rfx_compose_message_tile(RFX_CONTEXT* context, wStream* s, int CrLen = 0; int start_pos, end_pos; - stream_check_size(s, 19); + Stream_EnsureRemainingCapacity(s, 19); start_pos = Stream_GetPosition(s); stream_write_UINT16(s, CBT_TILE); /* BlockT.blockType */ @@ -1077,7 +1077,7 @@ static void rfx_compose_message_tileset(RFX_CONTEXT* context, wStream* s, numTiles = numTilesX * numTilesY; size = 22 + numQuants * 5; - stream_check_size(s, size); + Stream_EnsureRemainingCapacity(s, size); start_pos = Stream_GetPosition(s); stream_write_UINT16(s, WBT_EXTENSION); /* CodecChannelT.blockType */ @@ -1127,7 +1127,7 @@ static void rfx_compose_message_tileset(RFX_CONTEXT* context, wStream* s, static void rfx_compose_message_frame_end(RFX_CONTEXT* context, wStream* s) { - stream_check_size(s, 8); + Stream_EnsureRemainingCapacity(s, 8); stream_write_UINT16(s, WBT_FRAME_END); /* CodecChannelT.blockType */ stream_write_UINT32(s, 8); /* CodecChannelT.blockLen */ diff --git a/libfreerdp/codec/rfx_encode.c b/libfreerdp/codec/rfx_encode.c index 030d9fe04..b59570bec 100644 --- a/libfreerdp/codec/rfx_encode.c +++ b/libfreerdp/codec/rfx_encode.c @@ -242,18 +242,18 @@ void rfx_encode_rgb(RFX_CONTEXT* context, const BYTE* rgb_data, int width, int h PROFILER_EXIT(context->priv->prof_rfx_rgb_to_ycbcr); /* Ensure the buffer is reasonably large enough */ - stream_check_size(data_out, 4096); + Stream_EnsureRemainingCapacity(data_out, 4096); rfx_encode_component(context, y_quants, pSrcDst[0], Stream_Pointer(data_out), Stream_GetRemainingLength(data_out), y_size); Stream_Seek(data_out, *y_size); - stream_check_size(data_out, 4096); + Stream_EnsureRemainingCapacity(data_out, 4096); rfx_encode_component(context, cb_quants, pSrcDst[1], Stream_Pointer(data_out), Stream_GetRemainingLength(data_out), cb_size); Stream_Seek(data_out, *cb_size); - stream_check_size(data_out, 4096); + Stream_EnsureRemainingCapacity(data_out, 4096); rfx_encode_component(context, cr_quants, pSrcDst[2], Stream_Pointer(data_out), Stream_GetRemainingLength(data_out), cr_size); Stream_Seek(data_out, *cr_size); diff --git a/libfreerdp/core/channel.c b/libfreerdp/core/channel.c index 8342d0d62..307427dd8 100644 --- a/libfreerdp/core/channel.c +++ b/libfreerdp/core/channel.c @@ -80,7 +80,7 @@ BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channel_id, BYTE* data, int size) stream_write_UINT32(s, size); stream_write_UINT32(s, flags); - stream_check_size(s, chunk_size); + Stream_EnsureCapacity(s, chunk_size); stream_write(s, data, chunk_size); rdp_send(rdp, s, channel_id); diff --git a/libfreerdp/core/fastpath.c b/libfreerdp/core/fastpath.c index 6e9741a99..f8f92cde0 100644 --- a/libfreerdp/core/fastpath.c +++ b/libfreerdp/core/fastpath.c @@ -96,7 +96,7 @@ UINT16 fastpath_read_header(rdpFastPath* fastpath, wStream* s) stream_read_BYTE(s, header); - if (fastpath != NULL) + if (fastpath) { fastpath->encryptionFlags = (header & 0xC0) >> 6; fastpath->numberEvents = (header & 0x3C) >> 2; @@ -133,7 +133,7 @@ BOOL fastpath_read_header_rdp(rdpFastPath* fastpath, wStream* s, UINT16 *length) stream_read_BYTE(s, header); - if (fastpath != NULL) + if (fastpath) { fastpath->encryptionFlags = (header & 0xC0) >> 6; fastpath->numberEvents = (header & 0x3C) >> 2; @@ -157,6 +157,7 @@ static BOOL fastpath_recv_orders(rdpFastPath* fastpath, wStream* s) { if (!update_recv_order(update, s)) return FALSE; + numberOrders--; } @@ -500,6 +501,7 @@ static BOOL fastpath_recv_input_event_scancode(rdpFastPath* fastpath, wStream* s stream_read_BYTE(s, code); /* keyCode (1 byte) */ flags = 0; + if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE)) flags |= KBD_FLAGS_RELEASE; else @@ -567,6 +569,7 @@ static BOOL fastpath_recv_input_event_unicode(rdpFastPath* fastpath, wStream* s, stream_read_UINT16(s, unicodeCode); /* unicodeCode (2 bytes) */ flags = 0; + if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE)) flags |= KBD_FLAGS_RELEASE; else @@ -650,14 +653,16 @@ static UINT32 fastpath_get_sec_bytes(rdpRdp* rdp) { UINT32 sec_bytes; + sec_bytes = 0; + if (rdp->do_crypt) { sec_bytes = 8; + if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS) sec_bytes += 4; } - else - sec_bytes = 0; + return sec_bytes; } @@ -669,14 +674,20 @@ wStream* fastpath_input_pdu_init(rdpFastPath* fastpath, BYTE eventFlags, BYTE ev rdp = fastpath->rdp; s = transport_send_stream_init(rdp->transport, 256); + Stream_Seek(s, 3); /* fpInputHeader, length1 and length2 */ - if (rdp->do_crypt) { + + if (rdp->do_crypt) + { rdp->sec_flags |= SEC_ENCRYPT; + if (rdp->do_secure_checksum) rdp->sec_flags |= SEC_SECURE_CHECKSUM; } + Stream_Seek(s, fastpath_get_sec_bytes(rdp)); stream_write_BYTE(s, eventFlags | (eventCode << 5)); /* eventHeader (1 byte) */ + return s; } @@ -690,6 +701,7 @@ BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, wStream* s) rdp = fastpath->rdp; length = Stream_GetPosition(s); + if (length >= (2 << 14)) { fprintf(stderr, "Maximum FastPath PDU length is 32767\n"); @@ -698,6 +710,7 @@ BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, wStream* s) eventHeader = FASTPATH_INPUT_ACTION_FASTPATH; eventHeader |= (1 << 2); /* numberEvents */ + if (rdp->sec_flags & SEC_ENCRYPT) eventHeader |= (FASTPATH_INPUT_ENCRYPTED << 6); if (rdp->sec_flags & SEC_SECURE_CHECKSUM) @@ -706,8 +719,9 @@ BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, wStream* s) Stream_SetPosition(s, 0); stream_write_BYTE(s, eventHeader); sec_bytes = fastpath_get_sec_bytes(fastpath->rdp); + /* - * We always encode length in two bytes, eventhough we could use + * We always encode length in two bytes, even though we could use * only one byte if length <= 0x7F. It is just easier that way, * because we can leave room for fixed-length header, store all * the data first and then store the header. @@ -721,16 +735,19 @@ BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, wStream* s) fpInputEvents = Stream_Pointer(s) + sec_bytes; fpInputEvents_length = length - 3 - sec_bytes; + if (rdp->sec_flags & SEC_SECURE_CHECKSUM) security_salted_mac_signature(rdp, fpInputEvents, fpInputEvents_length, TRUE, Stream_Pointer(s)); else security_mac_signature(rdp, fpInputEvents, fpInputEvents_length, Stream_Pointer(s)); + security_encrypt(fpInputEvents, fpInputEvents_length, rdp); } rdp->sec_flags = 0; Stream_SetPosition(s, length); + if (transport_write(fastpath->rdp->transport, s) < 0) return FALSE; @@ -740,10 +757,13 @@ BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, wStream* s) wStream* fastpath_update_pdu_init(rdpFastPath* fastpath) { wStream* s; + s = transport_send_stream_init(fastpath->rdp->transport, FASTPATH_MAX_PACKET_SIZE); + Stream_Seek(s, 3); /* fpOutputHeader, length1 and length2 */ Stream_Seek(s, fastpath_get_sec_bytes(fastpath->rdp)); Stream_Seek(s, 3); /* updateHeader, size */ + return s; } @@ -783,7 +803,7 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s try_comp = rdp->settings->CompressionEnabled; comp_update = stream_new(0); - for (fragment = 0; totalLength > 0 || fragment == 0; fragment++) + for (fragment = 0; (totalLength > 0) || (fragment == 0); fragment++) { stream_get_mark(s, holdp); ls = s; @@ -792,6 +812,7 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s comp_flags = 0; header_bytes = 6 + sec_bytes; pdu_data_bytes = dlen; + if (try_comp) { if (compress_rdp(rdp->mppc_enc, ls->pointer + header_bytes, dlen)) @@ -808,7 +829,9 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s } } else + { fprintf(stderr, "fastpath_send_update_pdu: mppc_encode failed\n"); + } } totalLength -= dlen; @@ -821,8 +844,10 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s stream_get_mark(ls, bm); header = 0; + if (sec_bytes > 0) header |= (FASTPATH_OUTPUT_ENCRYPTED << 6); + stream_write_BYTE(ls, header); /* fpOutputHeader (1 byte) */ stream_write_BYTE(ls, 0x80 | (pduLength >> 8)); /* length1 */ stream_write_BYTE(ls, pduLength & 0xFF); /* length2 */ @@ -839,7 +864,9 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s bytes_to_crypt = pdu_data_bytes + 4; } else + { bytes_to_crypt = pdu_data_bytes + 3; + } stream_write_UINT16(ls, pdu_data_bytes); @@ -851,10 +878,12 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s /* does this work ? */ ptr_to_crypt = bm + 3 + sec_bytes; ptr_sig = bm + 3; + if (rdp->sec_flags & SEC_SECURE_CHECKSUM) security_salted_mac_signature(rdp, ptr_to_crypt, bytes_to_crypt, TRUE, ptr_sig); else security_mac_signature(rdp, ptr_to_crypt, bytes_to_crypt, ptr_sig); + security_encrypt(ptr_to_crypt, bytes_to_crypt, rdp); } diff --git a/libfreerdp/core/surface.c b/libfreerdp/core/surface.c index 909e722ff..3da81f25b 100644 --- a/libfreerdp/core/surface.c +++ b/libfreerdp/core/surface.c @@ -136,7 +136,7 @@ int update_recv_surfcmds(rdpUpdate* update, UINT32 size, wStream* s) void update_write_surfcmd_surface_bits_header(wStream* s, SURFACE_BITS_COMMAND* cmd) { - stream_check_size(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH); + Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH); stream_write_UINT16(s, CMDTYPE_STREAM_SURFACE_BITS); @@ -154,7 +154,7 @@ void update_write_surfcmd_surface_bits_header(wStream* s, SURFACE_BITS_COMMAND* void update_write_surfcmd_frame_marker(wStream* s, UINT16 frameAction, UINT32 frameId) { - stream_check_size(s, SURFCMD_FRAME_MARKER_LENGTH); + Stream_EnsureRemainingCapacity(s, SURFCMD_FRAME_MARKER_LENGTH); stream_write_UINT16(s, CMDTYPE_FRAME_MARKER); diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index 77bac1541..f364b60c1 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -53,7 +53,7 @@ static void* transport_client_thread(void* arg); wStream* transport_recv_stream_init(rdpTransport* transport, int size) { wStream* s = transport->ReceiveStream; - stream_check_size(s, size); + Stream_EnsureCapacity(s, size); Stream_SetPosition(s, 0); return s; } @@ -61,7 +61,7 @@ wStream* transport_recv_stream_init(rdpTransport* transport, int size) wStream* transport_send_stream_init(rdpTransport* transport, int size) { wStream* s = transport->SendStream; - stream_check_size(s, size); + Stream_EnsureCapacity(s, size); Stream_SetPosition(s, 0); return s; } @@ -498,7 +498,7 @@ static int transport_read_nonblocking(rdpTransport* transport) { int status; - stream_check_size(transport->ReceiveBuffer, 32 * 1024); + Stream_EnsureCapacity(transport->ReceiveBuffer, 32 * 1024); status = transport_read(transport, transport->ReceiveBuffer); if (status <= 0) diff --git a/libfreerdp/core/update.c b/libfreerdp/core/update.c index 44eee1bcd..d5565cbbc 100644 --- a/libfreerdp/core/update.c +++ b/libfreerdp/core/update.c @@ -511,7 +511,7 @@ static void update_send_surface_command(rdpContext* context, wStream* s) rdpRdp* rdp = context->rdp; update = fastpath_update_pdu_init(rdp->fastpath); - stream_check_size(update, Stream_GetPosition(s)); + Stream_EnsureRemainingCapacity(update, Stream_GetPosition(s)); stream_write(update, stream_get_head(s), Stream_GetPosition(s)); fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, update); } @@ -522,7 +522,7 @@ static void update_send_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* rdpRdp* rdp = context->rdp; s = fastpath_update_pdu_init(rdp->fastpath); - stream_check_size(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH + (int) surface_bits_command->bitmapDataLength); + Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH + (int) surface_bits_command->bitmapDataLength); update_write_surfcmd_surface_bits_header(s, surface_bits_command); stream_write(s, surface_bits_command->bitmapData, surface_bits_command->bitmapDataLength); fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s); @@ -610,7 +610,7 @@ static void update_send_pointer_system(rdpContext* context, POINTER_SYSTEM_UPDAT static void update_write_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color) { - stream_check_size(s, 15 + (int) pointer_color->lengthAndMask + (int) pointer_color->lengthXorMask); + Stream_EnsureRemainingCapacity(s, 15 + (int) pointer_color->lengthAndMask + (int) pointer_color->lengthXorMask); stream_write_UINT16(s, pointer_color->cacheIndex); stream_write_UINT16(s, pointer_color->xPos); @@ -674,6 +674,7 @@ BOOL update_read_refresh_rect(rdpUpdate* update, wStream* s) if (Stream_GetRemainingLength(s) < numberOfAreas * 4 * 2) return FALSE; + areas = (RECTANGLE_16*) malloc(sizeof(RECTANGLE_16) * numberOfAreas); for (index = 0; index < numberOfAreas; index++) diff --git a/libfreerdp/utils/rail.c b/libfreerdp/utils/rail.c index 162d95ef6..ba5529729 100644 --- a/libfreerdp/utils/rail.c +++ b/libfreerdp/utils/rail.c @@ -68,7 +68,7 @@ BOOL rail_read_unicode_string(wStream* s, RAIL_UNICODE_STRING* unicode_string) void rail_write_unicode_string(wStream* s, RAIL_UNICODE_STRING* unicode_string) { - stream_check_size(s, 2 + unicode_string->length); + Stream_EnsureRemainingCapacity(s, 2 + unicode_string->length); stream_write_UINT16(s, unicode_string->length); /* cbString (2 bytes) */ stream_write(s, unicode_string->string, unicode_string->length); /* string */ } @@ -77,7 +77,7 @@ void rail_write_unicode_string_value(wStream* s, RAIL_UNICODE_STRING* unicode_st { if (unicode_string->length > 0) { - stream_check_size(s, unicode_string->length); + Stream_EnsureRemainingCapacity(s, unicode_string->length); stream_write(s, unicode_string->string, unicode_string->length); /* string */ } } diff --git a/libfreerdp/utils/svc_plugin.c b/libfreerdp/utils/svc_plugin.c index 9dc0c9405..f201aec95 100644 --- a/libfreerdp/utils/svc_plugin.c +++ b/libfreerdp/utils/svc_plugin.c @@ -122,7 +122,7 @@ static void svc_plugin_process_received(rdpSvcPlugin* plugin, void* pData, UINT3 } data_in = plugin->data_in; - stream_check_size(data_in, (int) dataLength); + Stream_EnsureRemainingCapacity(data_in, (int) dataLength); stream_write(data_in, pData, dataLength); if (dataFlags & CHANNEL_FLAG_LAST) diff --git a/server/Mac/mf_peer.c b/server/Mac/mf_peer.c index 21e52a85a..9743162d0 100644 --- a/server/Mac/mf_peer.c +++ b/server/Mac/mf_peer.c @@ -133,7 +133,7 @@ void mf_peer_rfx_update(freerdp_peer* client) s = mfp->s; - stream_clear(s); + Stream_Clear(s); Stream_SetPosition(s, 0); UINT32 x = mfi->invalid.x / mfi->scale; diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index 370d1993d..47731ae48 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -104,7 +104,7 @@ static void test_peer_init(freerdp_peer* client) static wStream* test_peer_stream_init(testPeerContext* context) { - stream_clear(context->s); + Stream_Clear(context->s); Stream_SetPosition(context->s, 0); return context->s; } @@ -425,7 +425,7 @@ static void* tf_debug_channel_thread_func(void* arg) if (bytes_returned == 0) break; - stream_check_size(s, bytes_returned); + Stream_EnsureRemainingCapacity(s, bytes_returned); if (WTSVirtualChannelRead(context->debug_channel, 0, stream_get_head(s), Stream_Capacity(s), &bytes_returned) == FALSE) diff --git a/server/Windows/wf_update.c b/server/Windows/wf_update.c index 2e5c2b3c3..28c4b2bb1 100644 --- a/server/Windows/wf_update.c +++ b/server/Windows/wf_update.c @@ -134,7 +134,7 @@ void wf_update_encode(wfInfo* wfi) //printf("x:%d y:%d w:%d h:%d\n", wfi->invalid.left, wfi->invalid.top, width, height); - stream_clear(wfi->s); + Stream_Clear(wfi->s); rfx_compose_message(wfi->rfx_context, wfi->s, &rect, 1, pDataBits, width, height, stride); diff --git a/server/X11/xf_peer.c b/server/X11/xf_peer.c index da973296a..227ccee48 100644 --- a/server/X11/xf_peer.c +++ b/server/X11/xf_peer.c @@ -287,7 +287,8 @@ void xf_peer_context_new(freerdp_peer* client, xfPeerContext* context) rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8); - context->s = stream_new(65536); + context->s = Stream_New(NULL, 65536); + Stream_Clear(context->s); } void xf_peer_context_free(freerdp_peer* client, xfPeerContext* context) @@ -325,7 +326,7 @@ void xf_peer_init(freerdp_peer* client) wStream* xf_peer_stream_init(xfPeerContext* context) { - stream_clear(context->s); + Stream_Clear(context->s); Stream_SetPosition(context->s, 0); return context->s; } @@ -409,7 +410,7 @@ void xf_peer_rfx_update(freerdp_peer* client, int x, int y, int width, int heigh cmd->width = width; cmd->height = height; cmd->bitmapDataLength = Stream_GetPosition(s); - cmd->bitmapData = stream_get_head(s); + cmd->bitmapData = Stream_Buffer(s); update->SurfaceBits(update->context, cmd); } diff --git a/winpr/include/winpr/stream.h b/winpr/include/winpr/stream.h index cc9396959..5095496f9 100644 --- a/winpr/include/winpr/stream.h +++ b/winpr/include/winpr/stream.h @@ -43,6 +43,7 @@ struct _wStream typedef struct _wStream wStream; WINPR_API void Stream_EnsureCapacity(wStream* s, size_t size); +WINPR_API void Stream_EnsureRemainingCapacity(wStream* s, size_t size); WINPR_API wStream* Stream_New(BYTE* buffer, size_t size); WINPR_API void Stream_Free(wStream* s, BOOL bFreeBuffer); @@ -197,6 +198,8 @@ WINPR_API void Stream_Free(wStream* s, BOOL bFreeBuffer); #define Stream_SealLength(_s) _s->length = (_s->pointer - _s->buffer) #define Stream_GetRemainingLength(_s) (_s->length - (_s->pointer - _s->buffer)) +#define Stream_Clear(_s) memset(_s->buffer, 0, _s->capacity) + /* Deprecated STREAM API */ WINPR_API wStream* stream_new(int size); @@ -204,16 +207,12 @@ WINPR_API void stream_free(wStream* stream); #define stream_attach(_s, _buf, _size) do { \ _s->capacity = _size; \ - _s->length = _size; \ + _s->length = _size; \ _s->buffer = _buf; \ _s->pointer = _buf; } while (0) #define stream_detach(_s) memset(_s, 0, sizeof(wStream)) -#define stream_clear(_s) memset(_s->buffer, 0, _s->capacity) WINPR_API void stream_extend(wStream* stream, int request_size); -#define stream_check_size(_s, _n) \ - while (_s->pointer - _s->buffer + (_n) > _s->capacity) \ - stream_extend(_s, _n) #define stream_get_mark(_s,_mark) _mark = _s->pointer #define stream_set_mark(_s,_mark) _s->pointer = _mark diff --git a/winpr/libwinpr/utils/stream.c b/winpr/libwinpr/utils/stream.c index 380fcbda5..dc42af9c8 100644 --- a/winpr/libwinpr/utils/stream.c +++ b/winpr/libwinpr/utils/stream.c @@ -30,16 +30,28 @@ void Stream_EnsureCapacity(wStream* s, size_t size) if (s->capacity < size) { size_t position; + size_t old_capacity; + + old_capacity = s->capacity; + s->capacity = size; + s->length = size; position = Stream_GetPosition(s); - s->capacity = size; - s->buffer = (BYTE*) realloc(s->buffer, size); + s->buffer = (BYTE*) realloc(s->buffer, s->capacity); + + ZeroMemory(&s->buffer[old_capacity], s->capacity - old_capacity); Stream_SetPosition(s, position); } } +void Stream_EnsureRemainingCapacity(wStream* s, size_t size) +{ + if (Stream_GetPosition(s) + size > Stream_Capacity(s)) + Stream_EnsureCapacity(s, Stream_Capacity(s) + size); +} + wStream* Stream_New(BYTE* buffer, size_t size) { wStream* s; @@ -110,6 +122,7 @@ wStream* stream_new(int size) ZeroMemory(stream->buffer, size); stream->pointer = stream->buffer; stream->capacity = size; + stream->length = size; } } @@ -135,33 +148,3 @@ void stream_free(wStream* stream) free(stream); } } - -/** - * This function is used to extend the size of an existing stream. - * It will infact extend the attached buffer, fill the newly allocated region with 0, and reset the current - * stream position. - * If the stream did not have a buffer attached, a new one will be allocated and attached. - * - * @param stream [in/out] pointer to the STREAM structure that needs to be extended. - * @param request_size [in] Number of bytes to add to the existing stream. - * If the value is < the existing size, then the existing size is doubled. - */ -void stream_extend(wStream* stream, int request_size) -{ - int pos; - int original_size; - int increased_size; - - pos = Stream_GetPosition(stream); - original_size = stream->capacity; - increased_size = (request_size > original_size ? request_size : original_size); - stream->capacity += increased_size; - - if (original_size == 0) - stream->buffer = (BYTE*) malloc(stream->capacity); - else - stream->buffer = (BYTE*) realloc(stream->buffer, stream->capacity); - - memset(stream->buffer + original_size, 0, increased_size); - Stream_SetPosition(stream, pos); -}