Fixed #7350: Warnings with Stream_StaticInit

* Properly initialize the stream buffer
* Add Stream_StaticConstInit accepting a const buffer
* Modify API to return a pointer to the stream initialized
This commit is contained in:
akallabeth 2021-10-14 08:42:49 +02:00 committed by akallabeth
parent 98977336fd
commit 3ccb96d52f
12 changed files with 236 additions and 210 deletions

View File

@ -409,7 +409,8 @@ UINT cliprdr_read_format_list(wStream* s, CLIPRDR_FORMAT_LIST* formatList, BOOL
int formatNameLength;
char* szFormatName;
WCHAR* wszFormatName;
wStream sub1, sub2;
wStream sub1buffer = { 0 };
wStream* sub1;
CLIPRDR_FORMAT* formats = NULL;
UINT error = ERROR_INTERNAL_ERROR;
@ -420,7 +421,7 @@ UINT cliprdr_read_format_list(wStream* s, CLIPRDR_FORMAT_LIST* formatList, BOOL
formatList->formats = NULL;
formatList->numFormats = 0;
Stream_StaticInit(&sub1, Stream_Pointer(s), formatList->dataLen);
sub1 = Stream_StaticInit(&sub1buffer, Stream_Pointer(s), formatList->dataLen);
if (!Stream_SafeSeek(s, formatList->dataLen))
return ERROR_INVALID_DATA;
@ -429,7 +430,7 @@ UINT cliprdr_read_format_list(wStream* s, CLIPRDR_FORMAT_LIST* formatList, BOOL
}
else if (!useLongFormatNames)
{
const size_t cap = Stream_Capacity(&sub1);
const size_t cap = Stream_Capacity(sub1);
formatList->numFormats = (cap / 36);
if ((formatList->numFormats * 36) != cap)
@ -449,9 +450,9 @@ UINT cliprdr_read_format_list(wStream* s, CLIPRDR_FORMAT_LIST* formatList, BOOL
formatList->formats = formats;
while (Stream_GetRemainingLength(&sub1) >= 4)
while (Stream_GetRemainingLength(sub1) >= 4)
{
Stream_Read_UINT32(&sub1, formats[index].formatId); /* formatId (4 bytes) */
Stream_Read_UINT32(sub1, formats[index].formatId); /* formatId (4 bytes) */
formats[index].formatName = NULL;
@ -463,9 +464,9 @@ UINT cliprdr_read_format_list(wStream* s, CLIPRDR_FORMAT_LIST* formatList, BOOL
* These are 16 unicode charaters - *without* terminating null !
*/
szFormatName = (char*)Stream_Pointer(&sub1);
wszFormatName = (WCHAR*)Stream_Pointer(&sub1);
if (!Stream_SafeSeek(&sub1, 32))
szFormatName = (char*)Stream_Pointer(sub1);
wszFormatName = (WCHAR*)Stream_Pointer(sub1);
if (!Stream_SafeSeek(sub1, 32))
goto error_out;
if (asciiNames)
{
@ -505,18 +506,20 @@ UINT cliprdr_read_format_list(wStream* s, CLIPRDR_FORMAT_LIST* formatList, BOOL
}
else
{
sub2 = sub1;
while (Stream_GetRemainingLength(&sub1) > 0)
wStream sub2buffer = sub1buffer;
wStream* sub2 = &sub2buffer;
while (Stream_GetRemainingLength(sub1) > 0)
{
size_t rest;
if (!Stream_SafeSeek(&sub1, 4)) /* formatId (4 bytes) */
if (!Stream_SafeSeek(sub1, 4)) /* formatId (4 bytes) */
goto error_out;
wszFormatName = (WCHAR*)Stream_Pointer(&sub1);
rest = Stream_GetRemainingLength(&sub1);
wszFormatName = (WCHAR*)Stream_Pointer(sub1);
rest = Stream_GetRemainingLength(sub1);
formatNameLength = _wcsnlen(wszFormatName, rest / sizeof(WCHAR));
if (!Stream_SafeSeek(&sub1, (formatNameLength + 1) * sizeof(WCHAR)))
if (!Stream_SafeSeek(sub1, (formatNameLength + 1) * sizeof(WCHAR)))
goto error_out;
formatList->numFormats++;
}
@ -532,17 +535,17 @@ UINT cliprdr_read_format_list(wStream* s, CLIPRDR_FORMAT_LIST* formatList, BOOL
formatList->formats = formats;
while (Stream_GetRemainingLength(&sub2) >= 4)
while (Stream_GetRemainingLength(sub2) >= 4)
{
size_t rest;
Stream_Read_UINT32(&sub2, formats[index].formatId); /* formatId (4 bytes) */
Stream_Read_UINT32(sub2, formats[index].formatId); /* formatId (4 bytes) */
formats[index].formatName = NULL;
wszFormatName = (WCHAR*)Stream_Pointer(&sub2);
rest = Stream_GetRemainingLength(&sub2);
wszFormatName = (WCHAR*)Stream_Pointer(sub2);
rest = Stream_GetRemainingLength(sub2);
formatNameLength = _wcsnlen(wszFormatName, rest / sizeof(WCHAR));
if (!Stream_SafeSeek(&sub2, (formatNameLength + 1) * sizeof(WCHAR)))
if (!Stream_SafeSeek(sub2, (formatNameLength + 1) * sizeof(WCHAR)))
goto error_out;
if (formatNameLength)

View File

@ -2414,13 +2414,6 @@ INT32 progressive_decompress(PROGRESSIVE_CONTEXT* progressive, const BYTE* pSrcD
REGION16 clippingRects, updateRegion;
PROGRESSIVE_BLOCK_REGION* region = &progressive->region;
PROGRESSIVE_SURFACE_CONTEXT* surface = progressive_get_surface_data(progressive, surfaceId);
union
{
const BYTE* cbp;
BYTE* bp;
} sconv;
sconv.cbp = pSrcData;
if (!surface)
{
@ -2435,8 +2428,7 @@ INT32 progressive_decompress(PROGRESSIVE_CONTEXT* progressive, const BYTE* pSrcD
surface->numUpdatedTiles = 0;
}
Stream_StaticInit(&ss, sconv.bp, SrcSize);
s = &ss;
s = Stream_StaticConstInit(&ss, pSrcData, SrcSize);
switch (DstFormat)
{

View File

@ -903,7 +903,9 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa
for (i = 0; i < message->numTiles; i++)
{
wStream sub;
wStream subBuffer;
wStream* sub;
if (!(tile = (RFX_TILE*)ObjectPool_Take(context->priv->TilePool)))
{
WLog_ERR(TAG, "RfxMessageTileSet failed to get tile from object pool");
@ -922,17 +924,17 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa
break;
}
Stream_StaticInit(&sub, Stream_Pointer(s), Stream_GetRemainingLength(s));
Stream_Read_UINT16(&sub,
sub = Stream_StaticInit(&subBuffer, Stream_Pointer(s), Stream_GetRemainingLength(s));
Stream_Read_UINT16(sub,
blockType); /* blockType (2 bytes), must be set to CBT_TILE (0xCAC3) */
Stream_Read_UINT32(&sub, blockLen); /* blockLen (4 bytes) */
Stream_Read_UINT32(sub, blockLen); /* blockLen (4 bytes) */
if (!Stream_SafeSeek(s, blockLen))
{
rc = FALSE;
break;
}
if ((blockLen < 6 + 13) || (Stream_GetRemainingLength(&sub) < blockLen - 6))
if ((blockLen < 6 + 13) || (Stream_GetRemainingLength(sub) < blockLen - 6))
{
WLog_ERR(TAG,
"RfxMessageTileSet not enough bytes to read tile %d/%" PRIu16
@ -950,28 +952,28 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa
break;
}
Stream_Read_UINT8(&sub, tile->quantIdxY); /* quantIdxY (1 byte) */
Stream_Read_UINT8(&sub, tile->quantIdxCb); /* quantIdxCb (1 byte) */
Stream_Read_UINT8(&sub, tile->quantIdxCr); /* quantIdxCr (1 byte) */
Stream_Read_UINT16(&sub, tile->xIdx); /* xIdx (2 bytes) */
Stream_Read_UINT16(&sub, tile->yIdx); /* yIdx (2 bytes) */
Stream_Read_UINT16(&sub, tile->YLen); /* YLen (2 bytes) */
Stream_Read_UINT16(&sub, tile->CbLen); /* CbLen (2 bytes) */
Stream_Read_UINT16(&sub, tile->CrLen); /* CrLen (2 bytes) */
Stream_GetPointer(&sub, tile->YData);
if (!Stream_SafeSeek(&sub, tile->YLen))
Stream_Read_UINT8(sub, tile->quantIdxY); /* quantIdxY (1 byte) */
Stream_Read_UINT8(sub, tile->quantIdxCb); /* quantIdxCb (1 byte) */
Stream_Read_UINT8(sub, tile->quantIdxCr); /* quantIdxCr (1 byte) */
Stream_Read_UINT16(sub, tile->xIdx); /* xIdx (2 bytes) */
Stream_Read_UINT16(sub, tile->yIdx); /* yIdx (2 bytes) */
Stream_Read_UINT16(sub, tile->YLen); /* YLen (2 bytes) */
Stream_Read_UINT16(sub, tile->CbLen); /* CbLen (2 bytes) */
Stream_Read_UINT16(sub, tile->CrLen); /* CrLen (2 bytes) */
Stream_GetPointer(sub, tile->YData);
if (!Stream_SafeSeek(sub, tile->YLen))
{
rc = FALSE;
break;
}
Stream_GetPointer(&sub, tile->CbData);
if (!Stream_SafeSeek(&sub, tile->CbLen))
Stream_GetPointer(sub, tile->CbData);
if (!Stream_SafeSeek(sub, tile->CbLen))
{
rc = FALSE;
break;
}
Stream_GetPointer(&sub, tile->CrData);
if (!Stream_SafeSeek(&sub, tile->CrLen))
Stream_GetPointer(sub, tile->CrData);
if (!Stream_SafeSeek(sub, tile->CrLen))
{
rc = FALSE;
break;
@ -1039,7 +1041,7 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, UINT32 length,
REGION16 updateRegion;
UINT32 blockLen;
UINT32 blockType;
wStream inStream, *s = &inStream;
wStream inStream, *s;
BOOL ok = TRUE;
RFX_MESSAGE* message;
@ -1048,13 +1050,14 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, UINT32 length,
message = &context->currentMessage;
Stream_StaticInit(s, (BYTE*)data, length);
s = Stream_StaticConstInit(&inStream, data, length);
message->freeRects = TRUE;
while (ok && Stream_GetRemainingLength(s) > 6)
{
wStream subStream;
wStream subStreamBuffer;
wStream* subStream;
size_t extraBlockLen = 0;
/* RFX_BLOCKT */
@ -1123,7 +1126,8 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, UINT32 length,
}
}
Stream_StaticInit(&subStream, Stream_Pointer(s), blockLen - (6 + extraBlockLen));
subStream =
Stream_StaticInit(&subStreamBuffer, Stream_Pointer(s), blockLen - (6 + extraBlockLen));
Stream_Seek(s, blockLen - (6 + extraBlockLen));
switch (blockType)
@ -1133,19 +1137,19 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, UINT32 length,
* in the stream at a later stage. The header messages can be repeated.
*/
case WBT_SYNC:
ok = rfx_process_message_sync(context, &subStream);
ok = rfx_process_message_sync(context, subStream);
break;
case WBT_CONTEXT:
ok = rfx_process_message_context(context, &subStream);
ok = rfx_process_message_context(context, subStream);
break;
case WBT_CODEC_VERSIONS:
ok = rfx_process_message_codec_versions(context, &subStream);
ok = rfx_process_message_codec_versions(context, subStream);
break;
case WBT_CHANNELS:
ok = rfx_process_message_channels(context, &subStream);
ok = rfx_process_message_channels(context, subStream);
break;
/* Data messages:
@ -1156,22 +1160,22 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, UINT32 length,
*/
case WBT_FRAME_BEGIN:
ok = rfx_process_message_frame_begin(context, message, &subStream,
ok = rfx_process_message_frame_begin(context, message, subStream,
&context->expectedDataBlockType);
break;
case WBT_REGION:
ok = rfx_process_message_region(context, message, &subStream,
ok = rfx_process_message_region(context, message, subStream,
&context->expectedDataBlockType);
break;
case WBT_EXTENSION:
ok = rfx_process_message_tileset(context, message, &subStream,
ok = rfx_process_message_tileset(context, message, subStream,
&context->expectedDataBlockType);
break;
case WBT_FRAME_END:
ok = rfx_process_message_frame_end(context, message, &subStream,
ok = rfx_process_message_frame_end(context, message, subStream,
&context->expectedDataBlockType);
break;

View File

@ -2771,7 +2771,9 @@ static BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, rdpSettings* setti
while (bitmapCodecCount > 0)
{
size_t rest;
wStream sub;
wStream subbuffer;
wStream* sub;
if (!rdp_read_bitmap_codec_guid(s, &codecGuid)) /* codecGuid (16 bytes) */
return FALSE;
if (Stream_GetRemainingLength(s) < 3)
@ -2779,7 +2781,7 @@ static BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, rdpSettings* setti
Stream_Read_UINT8(s, codecId); /* codecId (1 byte) */
Stream_Read_UINT16(s, codecPropertiesLength); /* codecPropertiesLength (2 bytes) */
Stream_StaticInit(&sub, Stream_Pointer(s), codecPropertiesLength);
sub = Stream_StaticInit(&subbuffer, Stream_Pointer(s), codecPropertiesLength);
if (!Stream_SafeSeek(s, codecPropertiesLength))
return FALSE;
@ -2792,11 +2794,11 @@ static BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, rdpSettings* setti
UINT32 captureFlags;
guidRemoteFx = TRUE;
settings->RemoteFxCodecId = codecId;
if (Stream_GetRemainingLength(&sub) < 12)
if (Stream_GetRemainingLength(sub) < 12)
return FALSE;
Stream_Read_UINT32(&sub, rfxPropsLength); /* length (4 bytes) */
Stream_Read_UINT32(&sub, captureFlags); /* captureFlags (4 bytes) */
Stream_Read_UINT32(&sub, rfxCapsLength); /* capsLength (4 bytes) */
Stream_Read_UINT32(sub, rfxPropsLength); /* length (4 bytes) */
Stream_Read_UINT32(sub, captureFlags); /* captureFlags (4 bytes) */
Stream_Read_UINT32(sub, rfxCapsLength); /* capsLength (4 bytes) */
settings->RemoteFxCaptureFlags = captureFlags;
settings->RemoteFxOnly = (captureFlags & CARDP_CAPS_CAPTURE_NON_CAC) ? TRUE : FALSE;
@ -2810,11 +2812,11 @@ static BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, rdpSettings* setti
UINT16 numIcaps;
UINT16 icapLen;
/* TS_RFX_CAPS */
if (Stream_GetRemainingLength(&sub) < 21)
if (Stream_GetRemainingLength(sub) < 21)
return FALSE;
Stream_Read_UINT16(&sub, blockType); /* blockType (2 bytes) */
Stream_Read_UINT32(&sub, blockLen); /* blockLen (4 bytes) */
Stream_Read_UINT16(&sub, numCapsets); /* numCapsets (2 bytes) */
Stream_Read_UINT16(sub, blockType); /* blockType (2 bytes) */
Stream_Read_UINT32(sub, blockLen); /* blockLen (4 bytes) */
Stream_Read_UINT16(sub, numCapsets); /* numCapsets (2 bytes) */
if (blockType != 0xCBC0)
return FALSE;
@ -2826,12 +2828,12 @@ static BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, rdpSettings* setti
return FALSE;
/* TS_RFX_CAPSET */
Stream_Read_UINT16(&sub, blockType); /* blockType (2 bytes) */
Stream_Read_UINT32(&sub, blockLen); /* blockLen (4 bytes) */
Stream_Read_UINT8(&sub, rfxCodecId); /* codecId (1 byte) */
Stream_Read_UINT16(&sub, capsetType); /* capsetType (2 bytes) */
Stream_Read_UINT16(&sub, numIcaps); /* numIcaps (2 bytes) */
Stream_Read_UINT16(&sub, icapLen); /* icapLen (2 bytes) */
Stream_Read_UINT16(sub, blockType); /* blockType (2 bytes) */
Stream_Read_UINT32(sub, blockLen); /* blockLen (4 bytes) */
Stream_Read_UINT8(sub, rfxCodecId); /* codecId (1 byte) */
Stream_Read_UINT16(sub, capsetType); /* capsetType (2 bytes) */
Stream_Read_UINT16(sub, numIcaps); /* numIcaps (2 bytes) */
Stream_Read_UINT16(sub, icapLen); /* icapLen (2 bytes) */
if (blockType != 0xCBC1)
return FALSE;
@ -2851,14 +2853,14 @@ static BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, rdpSettings* setti
BYTE transformBits;
BYTE entropyBits;
/* TS_RFX_ICAP */
if (Stream_GetRemainingLength(&sub) < 8)
if (Stream_GetRemainingLength(sub) < 8)
return FALSE;
Stream_Read_UINT16(&sub, version); /* version (2 bytes) */
Stream_Read_UINT16(&sub, tileSize); /* tileSize (2 bytes) */
Stream_Read_UINT8(&sub, codecFlags); /* flags (1 byte) */
Stream_Read_UINT8(&sub, colConvBits); /* colConvBits (1 byte) */
Stream_Read_UINT8(&sub, transformBits); /* transformBits (1 byte) */
Stream_Read_UINT8(&sub, entropyBits); /* entropyBits (1 byte) */
Stream_Read_UINT16(sub, version); /* version (2 bytes) */
Stream_Read_UINT16(sub, tileSize); /* tileSize (2 bytes) */
Stream_Read_UINT8(sub, codecFlags); /* flags (1 byte) */
Stream_Read_UINT8(sub, colConvBits); /* colConvBits (1 byte) */
Stream_Read_UINT8(sub, transformBits); /* transformBits (1 byte) */
Stream_Read_UINT8(sub, entropyBits); /* entropyBits (1 byte) */
if (version == 0x0009)
{
@ -2887,7 +2889,7 @@ static BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, rdpSettings* setti
{
/* Microsoft RDP servers ignore CODEC_GUID_IMAGE_REMOTEFX codec properties */
guidRemoteFxImage = TRUE;
if (!Stream_SafeSeek(&sub, codecPropertiesLength)) /* codecProperties */
if (!Stream_SafeSeek(sub, codecPropertiesLength)) /* codecProperties */
return FALSE;
}
else if (UuidEqual(&codecGuid, &CODEC_GUID_NSCODEC, &rpc_status))
@ -2897,11 +2899,11 @@ static BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, rdpSettings* setti
BYTE fAllowDynamicFidelity;
guidNSCodec = TRUE;
settings->NSCodecId = codecId;
if (Stream_GetRemainingLength(&sub) < 3)
if (Stream_GetRemainingLength(sub) < 3)
return FALSE;
Stream_Read_UINT8(&sub, fAllowDynamicFidelity); /* fAllowDynamicFidelity (1 byte) */
Stream_Read_UINT8(&sub, fAllowSubsampling); /* fAllowSubsampling (1 byte) */
Stream_Read_UINT8(&sub, colorLossLevel); /* colorLossLevel (1 byte) */
Stream_Read_UINT8(sub, fAllowDynamicFidelity); /* fAllowDynamicFidelity (1 byte) */
Stream_Read_UINT8(sub, fAllowSubsampling); /* fAllowSubsampling (1 byte) */
Stream_Read_UINT8(sub, colorLossLevel); /* colorLossLevel (1 byte) */
if (colorLossLevel < 1)
colorLossLevel = 1;
@ -2915,22 +2917,22 @@ static BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, rdpSettings* setti
}
else if (UuidEqual(&codecGuid, &CODEC_GUID_IGNORE, &rpc_status))
{
if (!Stream_SafeSeek(&sub, codecPropertiesLength)) /* codecProperties */
if (!Stream_SafeSeek(sub, codecPropertiesLength)) /* codecProperties */
return FALSE;
}
else
{
if (!Stream_SafeSeek(&sub, codecPropertiesLength)) /* codecProperties */
if (!Stream_SafeSeek(sub, codecPropertiesLength)) /* codecProperties */
return FALSE;
}
}
else
{
if (!Stream_SafeSeek(&sub, codecPropertiesLength)) /* codecProperties */
if (!Stream_SafeSeek(sub, codecPropertiesLength)) /* codecProperties */
return FALSE;
}
rest = Stream_GetRemainingLength(&sub);
rest = Stream_GetRemainingLength(sub);
if (rest > 0)
{
WLog_ERR(TAG,
@ -3364,187 +3366,189 @@ static BOOL rdp_print_capability_sets(wStream* s, UINT16 numberCapabilities, BOO
while (numberCapabilities > 0)
{
size_t rest;
wStream sub;
wStream subBuffer;
wStream* sub;
if (!rdp_read_capability_set_header(s, &length, &type))
return FALSE;
WLog_INFO(TAG, "%s ", receiving ? "Receiving" : "Sending");
Stream_StaticInit(&sub, Stream_Pointer(s), length - 4);
sub = Stream_StaticInit(&subBuffer, Stream_Pointer(s), length - 4);
if (!Stream_SafeSeek(s, length - 4))
return FALSE;
switch (type)
{
case CAPSET_TYPE_GENERAL:
if (!rdp_print_general_capability_set(&sub))
if (!rdp_print_general_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_BITMAP:
if (!rdp_print_bitmap_capability_set(&sub))
if (!rdp_print_bitmap_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_ORDER:
if (!rdp_print_order_capability_set(&sub))
if (!rdp_print_order_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_BITMAP_CACHE:
if (!rdp_print_bitmap_cache_capability_set(&sub))
if (!rdp_print_bitmap_cache_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_CONTROL:
if (!rdp_print_control_capability_set(&sub))
if (!rdp_print_control_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_ACTIVATION:
if (!rdp_print_window_activation_capability_set(&sub))
if (!rdp_print_window_activation_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_POINTER:
if (!rdp_print_pointer_capability_set(&sub))
if (!rdp_print_pointer_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_SHARE:
if (!rdp_print_share_capability_set(&sub))
if (!rdp_print_share_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_COLOR_CACHE:
if (!rdp_print_color_cache_capability_set(&sub))
if (!rdp_print_color_cache_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_SOUND:
if (!rdp_print_sound_capability_set(&sub))
if (!rdp_print_sound_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_INPUT:
if (!rdp_print_input_capability_set(&sub))
if (!rdp_print_input_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_FONT:
if (!rdp_print_font_capability_set(&sub))
if (!rdp_print_font_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_BRUSH:
if (!rdp_print_brush_capability_set(&sub))
if (!rdp_print_brush_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_GLYPH_CACHE:
if (!rdp_print_glyph_cache_capability_set(&sub))
if (!rdp_print_glyph_cache_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_OFFSCREEN_CACHE:
if (!rdp_print_offscreen_bitmap_cache_capability_set(&sub))
if (!rdp_print_offscreen_bitmap_cache_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_BITMAP_CACHE_HOST_SUPPORT:
if (!rdp_print_bitmap_cache_host_support_capability_set(&sub))
if (!rdp_print_bitmap_cache_host_support_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_BITMAP_CACHE_V2:
if (!rdp_print_bitmap_cache_v2_capability_set(&sub))
if (!rdp_print_bitmap_cache_v2_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_VIRTUAL_CHANNEL:
if (!rdp_print_virtual_channel_capability_set(&sub))
if (!rdp_print_virtual_channel_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_DRAW_NINE_GRID_CACHE:
if (!rdp_print_draw_nine_grid_cache_capability_set(&sub))
if (!rdp_print_draw_nine_grid_cache_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_DRAW_GDI_PLUS:
if (!rdp_print_draw_gdiplus_cache_capability_set(&sub))
if (!rdp_print_draw_gdiplus_cache_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_RAIL:
if (!rdp_print_remote_programs_capability_set(&sub))
if (!rdp_print_remote_programs_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_WINDOW:
if (!rdp_print_window_list_capability_set(&sub))
if (!rdp_print_window_list_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_COMP_DESK:
if (!rdp_print_desktop_composition_capability_set(&sub))
if (!rdp_print_desktop_composition_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_MULTI_FRAGMENT_UPDATE:
if (!rdp_print_multifragment_update_capability_set(&sub))
if (!rdp_print_multifragment_update_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_LARGE_POINTER:
if (!rdp_print_large_pointer_capability_set(&sub))
if (!rdp_print_large_pointer_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_SURFACE_COMMANDS:
if (!rdp_print_surface_commands_capability_set(&sub))
if (!rdp_print_surface_commands_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_BITMAP_CODECS:
if (!rdp_print_bitmap_codecs_capability_set(&sub))
if (!rdp_print_bitmap_codecs_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_FRAME_ACKNOWLEDGE:
if (!rdp_print_frame_acknowledge_capability_set(&sub))
if (!rdp_print_frame_acknowledge_capability_set(sub))
return FALSE;
break;
case CAPSET_TYPE_BITMAP_CACHE_V3_CODEC_ID:
if (!rdp_print_bitmap_cache_v3_codec_id_capability_set(&sub))
if (!rdp_print_bitmap_cache_v3_codec_id_capability_set(sub))
return FALSE;
break;
@ -3554,7 +3558,7 @@ static BOOL rdp_print_capability_sets(wStream* s, UINT16 numberCapabilities, BOO
break;
}
rest = Stream_GetRemainingLength(&sub);
rest = Stream_GetRemainingLength(sub);
if (rest > 0)
{
WLog_WARN(TAG,
@ -3583,11 +3587,12 @@ static BOOL rdp_read_capability_sets(wStream* s, rdpSettings* settings, UINT16 n
size_t rest;
UINT16 type;
UINT16 length;
wStream sub;
wStream subbuffer;
wStream* sub;
if (!rdp_read_capability_set_header(s, &length, &type))
return FALSE;
Stream_StaticInit(&sub, Stream_Pointer(s), length - 4);
sub = Stream_StaticInit(&subbuffer, Stream_Pointer(s), length - 4);
if (!Stream_SafeSeek(s, length - 4))
return FALSE;
@ -3605,115 +3610,115 @@ static BOOL rdp_read_capability_sets(wStream* s, rdpSettings* settings, UINT16 n
switch (type)
{
case CAPSET_TYPE_GENERAL:
if (!rdp_read_general_capability_set(&sub, settings))
if (!rdp_read_general_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_BITMAP:
if (!rdp_read_bitmap_capability_set(&sub, settings))
if (!rdp_read_bitmap_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_ORDER:
if (!rdp_read_order_capability_set(&sub, settings))
if (!rdp_read_order_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_POINTER:
if (!rdp_read_pointer_capability_set(&sub, settings))
if (!rdp_read_pointer_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_INPUT:
if (!rdp_read_input_capability_set(&sub, settings))
if (!rdp_read_input_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_VIRTUAL_CHANNEL:
if (!rdp_read_virtual_channel_capability_set(&sub, settings))
if (!rdp_read_virtual_channel_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_SHARE:
if (!rdp_read_share_capability_set(&sub, settings))
if (!rdp_read_share_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_COLOR_CACHE:
if (!rdp_read_color_cache_capability_set(&sub, settings))
if (!rdp_read_color_cache_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_FONT:
if (!rdp_read_font_capability_set(&sub, settings))
if (!rdp_read_font_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_DRAW_GDI_PLUS:
if (!rdp_read_draw_gdiplus_cache_capability_set(&sub, settings))
if (!rdp_read_draw_gdiplus_cache_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_RAIL:
if (!rdp_read_remote_programs_capability_set(&sub, settings))
if (!rdp_read_remote_programs_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_WINDOW:
if (!rdp_read_window_list_capability_set(&sub, settings))
if (!rdp_read_window_list_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_MULTI_FRAGMENT_UPDATE:
if (!rdp_read_multifragment_update_capability_set(&sub, settings))
if (!rdp_read_multifragment_update_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_LARGE_POINTER:
if (!rdp_read_large_pointer_capability_set(&sub, settings))
if (!rdp_read_large_pointer_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_COMP_DESK:
if (!rdp_read_desktop_composition_capability_set(&sub, settings))
if (!rdp_read_desktop_composition_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_SURFACE_COMMANDS:
if (!rdp_read_surface_commands_capability_set(&sub, settings))
if (!rdp_read_surface_commands_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_BITMAP_CODECS:
if (!rdp_read_bitmap_codecs_capability_set(&sub, settings))
if (!rdp_read_bitmap_codecs_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_FRAME_ACKNOWLEDGE:
if (!rdp_read_frame_acknowledge_capability_set(&sub, settings))
if (!rdp_read_frame_acknowledge_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_BITMAP_CACHE_V3_CODEC_ID:
if (!rdp_read_bitmap_cache_v3_codec_id_capability_set(&sub, settings))
if (!rdp_read_bitmap_cache_v3_codec_id_capability_set(sub, settings))
return FALSE;
break;
@ -3731,55 +3736,55 @@ static BOOL rdp_read_capability_sets(wStream* s, rdpSettings* settings, UINT16 n
switch (type)
{
case CAPSET_TYPE_BITMAP_CACHE:
if (!rdp_read_bitmap_cache_capability_set(&sub, settings))
if (!rdp_read_bitmap_cache_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_BITMAP_CACHE_V2:
if (!rdp_read_bitmap_cache_v2_capability_set(&sub, settings))
if (!rdp_read_bitmap_cache_v2_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_BRUSH:
if (!rdp_read_brush_capability_set(&sub, settings))
if (!rdp_read_brush_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_GLYPH_CACHE:
if (!rdp_read_glyph_cache_capability_set(&sub, settings))
if (!rdp_read_glyph_cache_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_OFFSCREEN_CACHE:
if (!rdp_read_offscreen_bitmap_cache_capability_set(&sub, settings))
if (!rdp_read_offscreen_bitmap_cache_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_SOUND:
if (!rdp_read_sound_capability_set(&sub, settings))
if (!rdp_read_sound_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_CONTROL:
if (!rdp_read_control_capability_set(&sub, settings))
if (!rdp_read_control_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_ACTIVATION:
if (!rdp_read_window_activation_capability_set(&sub, settings))
if (!rdp_read_window_activation_capability_set(sub, settings))
return FALSE;
break;
case CAPSET_TYPE_DRAW_NINE_GRID_CACHE:
if (!rdp_read_draw_nine_grid_cache_capability_set(&sub, settings))
if (!rdp_read_draw_nine_grid_cache_capability_set(sub, settings))
return FALSE;
break;
@ -3796,7 +3801,7 @@ static BOOL rdp_read_capability_sets(wStream* s, rdpSettings* settings, UINT16 n
switch (type)
{
case CAPSET_TYPE_BITMAP_CACHE_HOST_SUPPORT:
if (!rdp_read_bitmap_cache_host_support_capability_set(&sub, settings))
if (!rdp_read_bitmap_cache_host_support_capability_set(sub, settings))
return FALSE;
break;
@ -3809,7 +3814,7 @@ static BOOL rdp_read_capability_sets(wStream* s, rdpSettings* settings, UINT16 n
}
}
rest = Stream_GetRemainingLength(&sub);
rest = Stream_GetRemainingLength(sub);
if (rest > 0)
{
WLog_ERR(TAG,

View File

@ -555,7 +555,8 @@ BOOL gcc_read_server_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length)
while (offset < length)
{
size_t rest;
wStream sub;
wStream subbuffer;
wStream* sub;
if (!gcc_read_user_data_header(s, &type, &blockLength))
{
@ -563,7 +564,7 @@ BOOL gcc_read_server_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length)
return FALSE;
}
holdp = Stream_Pointer(s);
Stream_StaticInit(&sub, holdp, blockLength - 4);
sub = Stream_StaticInit(&subbuffer, holdp, blockLength - 4);
if (!Stream_SafeSeek(s, blockLength - 4))
{
WLog_ERR(TAG, "gcc_read_server_data_blocks: stream too short");
@ -574,7 +575,7 @@ BOOL gcc_read_server_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length)
switch (type)
{
case SC_CORE:
if (!gcc_read_server_core_data(&sub, mcs))
if (!gcc_read_server_core_data(sub, mcs))
{
WLog_ERR(TAG, "gcc_read_server_data_blocks: gcc_read_server_core_data failed");
return FALSE;
@ -583,7 +584,7 @@ BOOL gcc_read_server_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length)
break;
case SC_SECURITY:
if (!gcc_read_server_security_data(&sub, mcs))
if (!gcc_read_server_security_data(sub, mcs))
{
WLog_ERR(TAG,
"gcc_read_server_data_blocks: gcc_read_server_security_data failed");
@ -593,7 +594,7 @@ BOOL gcc_read_server_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length)
break;
case SC_NET:
if (!gcc_read_server_network_data(&sub, mcs))
if (!gcc_read_server_network_data(sub, mcs))
{
WLog_ERR(TAG,
"gcc_read_server_data_blocks: gcc_read_server_network_data failed");
@ -603,7 +604,7 @@ BOOL gcc_read_server_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length)
break;
case SC_MCS_MSGCHANNEL:
if (!gcc_read_server_message_channel_data(&sub, mcs))
if (!gcc_read_server_message_channel_data(sub, mcs))
{
WLog_ERR(
TAG,
@ -614,7 +615,7 @@ BOOL gcc_read_server_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length)
break;
case SC_MULTITRANSPORT:
if (!gcc_read_server_multitransport_channel_data(&sub, mcs))
if (!gcc_read_server_multitransport_channel_data(sub, mcs))
{
WLog_ERR(TAG, "gcc_read_server_data_blocks: "
"gcc_read_server_multitransport_channel_data failed");
@ -628,7 +629,7 @@ BOOL gcc_read_server_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length)
break;
}
rest = Stream_GetRemainingLength(&sub);
rest = Stream_GetRemainingLength(sub);
if (rest > 0)
{
WLog_WARN(

View File

@ -627,11 +627,12 @@ BOOL license_generate_hwid(rdpLicense* license)
}
else
{
wStream s;
wStream buffer;
wStream* s;
const char* hostname = license->rdp->settings->ClientHostname;
Stream_StaticInit(&s, license->HardwareId, 4);
Stream_Write_UINT32(&s, PLATFORMID);
Stream_Free(&s, TRUE);
s = Stream_StaticInit(&buffer, license->HardwareId, 4);
Stream_Write_UINT32(s, PLATFORMID);
Stream_Free(s, TRUE);
hashTarget = (const BYTE*)hostname;
targetLen = strlen(hostname);

View File

@ -1858,7 +1858,8 @@ static BOOL update_read_fast_glyph_order(wStream* s, const ORDER_INFO* orderInfo
if ((orderInfo->fieldFlags & ORDER_FIELD_15) != 0)
{
const BYTE* src;
wStream sub;
wStream subbuffer;
wStream* sub;
if (Stream_GetRemainingLength(s) < 1)
return FALSE;
@ -1869,16 +1870,16 @@ static BOOL update_read_fast_glyph_order(wStream* s, const ORDER_INFO* orderInfo
return FALSE;
CopyMemory(fastGlyph->data, src, fastGlyph->cbData);
Stream_StaticInit(&sub, fastGlyph->data, fastGlyph->cbData);
sub = Stream_StaticInit(&subbuffer, fastGlyph->data, fastGlyph->cbData);
Stream_Read_UINT8(&sub, glyph->cacheIndex);
Stream_Read_UINT8(sub, glyph->cacheIndex);
if (fastGlyph->cbData > 1)
{
if (!update_read_2byte_signed(&sub, &glyph->x) ||
!update_read_2byte_signed(&sub, &glyph->y) ||
!update_read_2byte_unsigned(&sub, &glyph->cx) ||
!update_read_2byte_unsigned(&sub, &glyph->cy))
if (!update_read_2byte_signed(sub, &glyph->x) ||
!update_read_2byte_signed(sub, &glyph->y) ||
!update_read_2byte_unsigned(sub, &glyph->cx) ||
!update_read_2byte_unsigned(sub, &glyph->cy))
return FALSE;
if ((glyph->cx == 0) || (glyph->cy == 0))
@ -1888,7 +1889,7 @@ static BOOL update_read_fast_glyph_order(wStream* s, const ORDER_INFO* orderInfo
return FALSE;
}
glyph->cb = Stream_GetRemainingLength(&sub);
glyph->cb = Stream_GetRemainingLength(sub);
if (glyph->cb > 0)
{
BYTE* new_aj = (BYTE*)realloc(glyph->aj, glyph->cb);
@ -1897,7 +1898,7 @@ static BOOL update_read_fast_glyph_order(wStream* s, const ORDER_INFO* orderInfo
return FALSE;
glyph->aj = new_aj;
Stream_Read(&sub, glyph->aj, glyph->cb);
Stream_Read(sub, glyph->aj, glyph->cb);
}
else
{

View File

@ -1367,7 +1367,8 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
{
while (Stream_GetRemainingLength(s) > 3)
{
wStream sub;
wStream subbuffer;
wStream* sub;
size_t diff;
UINT16 remain;
@ -1377,7 +1378,7 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
return -1;
}
Stream_StaticInit(&sub, Stream_Pointer(s), remain);
sub = Stream_StaticInit(&subbuffer, Stream_Pointer(s), remain);
if (!Stream_SafeSeek(s, remain))
return -1;
@ -1387,13 +1388,13 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
switch (pduType)
{
case PDU_TYPE_DATA:
rc = rdp_recv_data_pdu(rdp, &sub);
rc = rdp_recv_data_pdu(rdp, sub);
if (rc < 0)
return rc;
break;
case PDU_TYPE_DEACTIVATE_ALL:
if (!rdp_recv_deactivate_all(rdp, &sub))
if (!rdp_recv_deactivate_all(rdp, sub))
{
WLog_ERR(TAG, "rdp_recv_tpkt_pdu: rdp_recv_deactivate_all() fail");
return -1;
@ -1402,14 +1403,14 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
break;
case PDU_TYPE_SERVER_REDIRECTION:
return rdp_recv_enhanced_security_redirection_packet(rdp, &sub);
return rdp_recv_enhanced_security_redirection_packet(rdp, sub);
case PDU_TYPE_FLOW_RESPONSE:
case PDU_TYPE_FLOW_STOP:
case PDU_TYPE_FLOW_TEST:
WLog_DBG(TAG, "flow message 0x%04" PRIX16 "", pduType);
/* http://msdn.microsoft.com/en-us/library/cc240576.aspx */
if (!Stream_SafeSeek(&sub, remain))
if (!Stream_SafeSeek(sub, remain))
return -1;
break;
@ -1418,7 +1419,7 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
break;
}
diff = Stream_GetRemainingLength(&sub);
diff = Stream_GetRemainingLength(sub);
if (diff > 0)
{
WLog_WARN(TAG,

View File

@ -777,13 +777,15 @@ static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context,
UINT16 alphaSig, compressed;
gdiGfxSurface* surface;
RECTANGLE_16 invalidRect;
wStream s;
wStream buffer;
wStream* s;
WINPR_ASSERT(gdi);
WINPR_ASSERT(context);
WINPR_ASSERT(cmd);
Stream_StaticInit(&s, cmd->data, cmd->length);
if (Stream_GetRemainingLength(&s) < 4)
s = Stream_StaticConstInit(&buffer, cmd->data, cmd->length);
if (Stream_GetRemainingLength(s) < 4)
return ERROR_INVALID_DATA;
surface = (gdiGfxSurface*)context->GetSurfaceData(context, cmd->surfaceId);
@ -798,8 +800,8 @@ static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context,
if (!is_within_surface(surface, cmd))
return ERROR_INVALID_DATA;
Stream_Read_UINT16(&s, alphaSig);
Stream_Read_UINT16(&s, compressed);
Stream_Read_UINT16(s, alphaSig);
Stream_Read_UINT16(s, compressed);
if (alphaSig != 0x414C)
return ERROR_INVALID_DATA;
@ -808,19 +810,19 @@ static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context,
{
UINT32 x, y;
if (Stream_GetRemainingLength(&s) < cmd->height * cmd->width * 1ULL)
if (Stream_GetRemainingLength(s) < cmd->height * cmd->width * 1ULL)
return ERROR_INVALID_DATA;
for (y = cmd->top; y < cmd->top + cmd->height; y++)
{
BYTE* line = &surface->data[surface->scanline * y];
BYTE* line = surface->data[surface->scanline * y];
for (x = cmd->left; x < cmd->left + cmd->width; x++)
{
UINT32 color;
BYTE r, g, b, a;
BYTE* src = &line[x * GetBytesPerPixel(surface->format)];
Stream_Read_UINT8(&s, a);
Stream_Read_UINT8(s, a);
color = ReadColor(src, surface->format);
SplitColor(color, surface->format, &r, &g, &b, NULL, NULL);
color = FreeRDPGetColor(surface->format, r, g, b, a);
@ -842,25 +844,25 @@ static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context,
UINT32 count;
BYTE a;
if (Stream_GetRemainingLength(&s) < 2)
if (Stream_GetRemainingLength(s) < 2)
return ERROR_INVALID_DATA;
Stream_Read_UINT8(&s, a);
Stream_Read_UINT8(&s, count);
Stream_Read_UINT8(s, a);
Stream_Read_UINT8(s, count);
if (count >= 0xFF)
{
if (Stream_GetRemainingLength(&s) < 2)
if (Stream_GetRemainingLength(s) < 2)
return ERROR_INVALID_DATA;
Stream_Read_UINT16(&s, count);
Stream_Read_UINT16(s, count);
if (count >= 0xFFFF)
{
if (Stream_GetRemainingLength(&s) < 4)
if (Stream_GetRemainingLength(s) < 4)
return ERROR_INVALID_DATA;
Stream_Read_UINT32(&s, count);
Stream_Read_UINT32(s, count);
}
}

View File

@ -58,7 +58,8 @@ extern "C"
WINPR_API BOOL Stream_EnsureRemainingCapacity(wStream* s, size_t size);
WINPR_API wStream* Stream_New(BYTE* buffer, size_t size);
WINPR_API void Stream_StaticInit(wStream* s, BYTE* buffer, size_t size);
WINPR_API wStream* Stream_StaticConstInit(wStream* s, const BYTE* buffer, size_t size);
WINPR_API wStream* Stream_StaticInit(wStream* s, BYTE* buffer, size_t size);
WINPR_API void Stream_Free(wStream* s, BOOL bFreeBuffer);
static INLINE void Stream_Seek(wStream* s, size_t _offset)

View File

@ -103,22 +103,20 @@ static BOOL readBitmapInfoHeader(wStream* s, WINPR_BITMAP_INFO_HEADER* bi)
BYTE* winpr_bitmap_construct_header(size_t width, size_t height, size_t bpp)
{
BYTE* result = NULL;
WINPR_BITMAP_FILE_HEADER bf;
WINPR_BITMAP_INFO_HEADER bi;
wStream s;
wStream* s;
size_t imgSize;
BYTE* buffer = NULL;
imgSize = width * height * (bpp / 8);
if ((width > INT32_MAX) || (height > INT32_MAX) || (bpp > UINT16_MAX) || (imgSize > UINT32_MAX))
return NULL;
buffer = malloc(WINPR_IMAGE_BMP_HEADER_LEN);
if (!buffer)
s = Stream_New(NULL, WINPR_IMAGE_BMP_HEADER_LEN);
if (!s)
return NULL;
Stream_StaticInit(&s, buffer, WINPR_IMAGE_BMP_HEADER_LEN);
bf.bfType[0] = 'B';
bf.bfType[1] = 'M';
bf.bfReserved1 = 0;
@ -137,15 +135,16 @@ BYTE* winpr_bitmap_construct_header(size_t width, size_t height, size_t bpp)
bi.biClrImportant = 0;
bi.biSize = (UINT32)sizeof(WINPR_BITMAP_INFO_HEADER);
if (!writeBitmapFileHeader(&s, &bf))
if (!writeBitmapFileHeader(s, &bf))
goto fail;
if (!writeBitmapInfoHeader(&s, &bi))
if (!writeBitmapInfoHeader(s, &bi))
goto fail;
return buffer;
result = Stream_Buffer(s);
fail:
return NULL;
Stream_Free(s, result == 0);
return result;
}
/**

View File

@ -126,17 +126,33 @@ wStream* Stream_New(BYTE* buffer, size_t size)
return s;
}
void Stream_StaticInit(wStream* s, BYTE* buffer, size_t size)
wStream* Stream_StaticConstInit(wStream* s, const BYTE* buffer, size_t size)
{
union
{
BYTE* b;
const BYTE* cb;
} cnv;
cnv.cb = buffer;
return Stream_StaticInit(s, cnv.b, size);
}
wStream* Stream_StaticInit(wStream* s, BYTE* buffer, size_t size)
{
const wStream empty = { 0 };
WINPR_ASSERT(s);
WINPR_ASSERT(buffer);
*s = empty;
s->buffer = s->pointer = buffer;
s->capacity = s->length = size;
s->pool = NULL;
s->count = 0;
s->isAllocatedStream = FALSE;
s->isOwner = FALSE;
return s;
}
void Stream_EnsureValidity(wStream* s)