Skip to content

Commit 2a707c9

Browse files
committed
Fix encoding failure for some cases.
This commit ensures at least 4 bytes remains in the buffer for utf8 encoding.
1 parent 76625cc commit 2a707c9

7 files changed

Lines changed: 58 additions & 49 deletions

src/MsgPack/ByteArrayPackerWriter.TypedWrite.cs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ namespace MsgPack
4242

4343
partial class ByteArrayPackerWriter
4444
{
45+
private const int MaximumUtf8Length = 4;
46+
4547
public override void WriteBytes( byte header, byte value )
4648
{
4749
var currentBuffer = this._currentBuffer;
4850
var currentBufferOffset = this._currentBufferOffset;
4951
var currentBufferLimit = this._currentBufferLimit;
5052
var currentBufferIndex = this._currentBufferIndex;
51-
if ( !this.ShiftBufferIfNeeded( sizeof( byte ) + 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
53+
if ( !this.ShiftBufferIfNeeded( sizeof( byte ) + 1, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
5254
{
5355
this.ThrowEofException( sizeof( byte ) );
5456
}
@@ -75,7 +77,7 @@ public override void WriteBytes( byte header, byte value )
7577

7678
private void WriteBytesSlow( byte value, ref int currentBufferIndex, ref byte[] currentBuffer, ref int currentBufferOffset, ref int currentBufferLimit )
7779
{
78-
if ( !this.ShiftBufferIfNeeded( sizeof( byte ), ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
80+
if ( !this.ShiftBufferIfNeeded( sizeof( byte ), 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
7981
{
8082
this.ThrowEofException( sizeof( byte ) );
8183
}
@@ -92,7 +94,7 @@ private void WriteBytesSlow( byte value, ref int currentBufferIndex, ref byte[]
9294

9395
currentBufferOffset += currentWritten;
9496

95-
if ( !this.ShiftBufferIfNeeded( sizeof( byte ) - totalWritten, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
97+
if ( !this.ShiftBufferIfNeeded( sizeof( byte ) - totalWritten, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
9698
{
9799
this.ThrowEofException( sizeof( byte ) );
98100
}
@@ -107,7 +109,7 @@ public override void WriteBytes( byte header, ushort value )
107109
var currentBufferOffset = this._currentBufferOffset;
108110
var currentBufferLimit = this._currentBufferLimit;
109111
var currentBufferIndex = this._currentBufferIndex;
110-
if ( !this.ShiftBufferIfNeeded( sizeof( ushort ) + 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
112+
if ( !this.ShiftBufferIfNeeded( sizeof( ushort ) + 1, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
111113
{
112114
this.ThrowEofException( sizeof( ushort ) );
113115
}
@@ -135,7 +137,7 @@ public override void WriteBytes( byte header, ushort value )
135137

136138
private void WriteBytesSlow( ushort value, ref int currentBufferIndex, ref byte[] currentBuffer, ref int currentBufferOffset, ref int currentBufferLimit )
137139
{
138-
if ( !this.ShiftBufferIfNeeded( sizeof( ushort ), ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
140+
if ( !this.ShiftBufferIfNeeded( sizeof( ushort ), 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
139141
{
140142
this.ThrowEofException( sizeof( ushort ) );
141143
}
@@ -152,7 +154,7 @@ private void WriteBytesSlow( ushort value, ref int currentBufferIndex, ref byte[
152154

153155
currentBufferOffset += currentWritten;
154156

155-
if ( !this.ShiftBufferIfNeeded( sizeof( ushort ) - totalWritten, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
157+
if ( !this.ShiftBufferIfNeeded( sizeof( ushort ) - totalWritten, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
156158
{
157159
this.ThrowEofException( sizeof( ushort ) );
158160
}
@@ -167,7 +169,7 @@ public override void WriteBytes( byte header, uint value )
167169
var currentBufferOffset = this._currentBufferOffset;
168170
var currentBufferLimit = this._currentBufferLimit;
169171
var currentBufferIndex = this._currentBufferIndex;
170-
if ( !this.ShiftBufferIfNeeded( sizeof( uint ) + 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
172+
if ( !this.ShiftBufferIfNeeded( sizeof( uint ) + 1, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
171173
{
172174
this.ThrowEofException( sizeof( uint ) );
173175
}
@@ -197,7 +199,7 @@ public override void WriteBytes( byte header, uint value )
197199

198200
private void WriteBytesSlow( uint value, ref int currentBufferIndex, ref byte[] currentBuffer, ref int currentBufferOffset, ref int currentBufferLimit )
199201
{
200-
if ( !this.ShiftBufferIfNeeded( sizeof( uint ), ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
202+
if ( !this.ShiftBufferIfNeeded( sizeof( uint ), 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
201203
{
202204
this.ThrowEofException( sizeof( uint ) );
203205
}
@@ -214,7 +216,7 @@ private void WriteBytesSlow( uint value, ref int currentBufferIndex, ref byte[]
214216

215217
currentBufferOffset += currentWritten;
216218

217-
if ( !this.ShiftBufferIfNeeded( sizeof( uint ) - totalWritten, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
219+
if ( !this.ShiftBufferIfNeeded( sizeof( uint ) - totalWritten, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
218220
{
219221
this.ThrowEofException( sizeof( uint ) );
220222
}
@@ -229,7 +231,7 @@ public override void WriteBytes( byte header, ulong value )
229231
var currentBufferOffset = this._currentBufferOffset;
230232
var currentBufferLimit = this._currentBufferLimit;
231233
var currentBufferIndex = this._currentBufferIndex;
232-
if ( !this.ShiftBufferIfNeeded( sizeof( ulong ) + 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
234+
if ( !this.ShiftBufferIfNeeded( sizeof( ulong ) + 1, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
233235
{
234236
this.ThrowEofException( sizeof( ulong ) );
235237
}
@@ -263,7 +265,7 @@ public override void WriteBytes( byte header, ulong value )
263265

264266
private void WriteBytesSlow( ulong value, ref int currentBufferIndex, ref byte[] currentBuffer, ref int currentBufferOffset, ref int currentBufferLimit )
265267
{
266-
if ( !this.ShiftBufferIfNeeded( sizeof( ulong ), ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
268+
if ( !this.ShiftBufferIfNeeded( sizeof( ulong ), 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
267269
{
268270
this.ThrowEofException( sizeof( ulong ) );
269271
}
@@ -280,7 +282,7 @@ private void WriteBytesSlow( ulong value, ref int currentBufferIndex, ref byte[]
280282

281283
currentBufferOffset += currentWritten;
282284

283-
if ( !this.ShiftBufferIfNeeded( sizeof( ulong ) - totalWritten, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
285+
if ( !this.ShiftBufferIfNeeded( sizeof( ulong ) - totalWritten, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
284286
{
285287
this.ThrowEofException( sizeof( ulong ) );
286288
}
@@ -296,7 +298,7 @@ public override void WriteBytes( byte header, float value )
296298
var currentBufferOffset = this._currentBufferOffset;
297299
var currentBufferLimit = this._currentBufferLimit;
298300
var currentBufferIndex = this._currentBufferIndex;
299-
if ( !this.ShiftBufferIfNeeded( sizeof( float ) + 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
301+
if ( !this.ShiftBufferIfNeeded( sizeof( float ) + 1, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
300302
{
301303
this.ThrowEofException( sizeof( float ) );
302304
}
@@ -326,7 +328,7 @@ public override void WriteBytes( byte header, float value )
326328

327329
private void WriteBytesSlow( int value, ref int currentBufferIndex, ref byte[] currentBuffer, ref int currentBufferOffset, ref int currentBufferLimit )
328330
{
329-
if ( !this.ShiftBufferIfNeeded( sizeof( float ), ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
331+
if ( !this.ShiftBufferIfNeeded( sizeof( float ), 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
330332
{
331333
this.ThrowEofException( sizeof( float ) );
332334
}
@@ -343,7 +345,7 @@ private void WriteBytesSlow( int value, ref int currentBufferIndex, ref byte[] c
343345

344346
currentBufferOffset += currentWritten;
345347

346-
if ( !this.ShiftBufferIfNeeded( sizeof( float ) - totalWritten, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
348+
if ( !this.ShiftBufferIfNeeded( sizeof( float ) - totalWritten, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
347349
{
348350
this.ThrowEofException( sizeof( float ) );
349351
}
@@ -359,7 +361,7 @@ public override void WriteBytes( byte header, double value )
359361
var currentBufferOffset = this._currentBufferOffset;
360362
var currentBufferLimit = this._currentBufferLimit;
361363
var currentBufferIndex = this._currentBufferIndex;
362-
if ( !this.ShiftBufferIfNeeded( sizeof( double ) + 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
364+
if ( !this.ShiftBufferIfNeeded( sizeof( double ) + 1, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
363365
{
364366
this.ThrowEofException( sizeof( double ) );
365367
}
@@ -393,7 +395,7 @@ public override void WriteBytes( byte header, double value )
393395

394396
private void WriteBytesSlow( long value, ref int currentBufferIndex, ref byte[] currentBuffer, ref int currentBufferOffset, ref int currentBufferLimit )
395397
{
396-
if ( !this.ShiftBufferIfNeeded( sizeof( double ), ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
398+
if ( !this.ShiftBufferIfNeeded( sizeof( double ), 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
397399
{
398400
this.ThrowEofException( sizeof( double ) );
399401
}
@@ -410,7 +412,7 @@ private void WriteBytesSlow( long value, ref int currentBufferIndex, ref byte[]
410412

411413
currentBufferOffset += currentWritten;
412414

413-
if ( !this.ShiftBufferIfNeeded( sizeof( double ) - totalWritten, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
415+
if ( !this.ShiftBufferIfNeeded( sizeof( double ) - totalWritten, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
414416
{
415417
this.ThrowEofException( sizeof( double ) );
416418
}
@@ -436,7 +438,7 @@ public override void WriteBytes( string value, bool allowStr8 )
436438
}
437439
else
438440
{
439-
this.WriteStringBody( value );
441+
this.WriteStringBody( value, encodedLength );
440442
}
441443
}
442444

@@ -509,7 +511,7 @@ private void WriteStringHeader( int bytesLength, bool allowStr8 )
509511
}
510512

511513
#if !FEATURE_POINTER_CONVERSION
512-
private void WriteStringBody( string value )
514+
private void WriteStringBody( string value, int encodedLength )
513515
{
514516
var chars = BufferManager.NewCharBuffer( value.Length );
515517
int offset = 0;
@@ -518,16 +520,16 @@ private void WriteStringBody( string value )
518520
{
519521
int copying = Math.Min( value.Length - offset, chars.Length );
520522
value.CopyTo( offset, chars, 0, copying );
521-
this.WriteStringBody( chars, copying );
523+
this.WriteStringBody( chars, copying, encodedLength );
522524
offset += copying;
523525
}
524526
}
525527

526-
private void WriteStringBody( char[] value, int remainingCharsLength )
528+
private void WriteStringBody( char[] value, int remainingCharsLength, int encodedLength )
527529
{
528530
var charsOffset = 0;
529531
#else
530-
private unsafe void WriteStringBody( string value )
532+
private unsafe void WriteStringBody( string value, int encodedLength )
531533
{
532534
fixed ( char* pValue = value )
533535
#endif // !FEATURE_POINTER_CONVERSION
@@ -541,12 +543,13 @@ private unsafe void WriteStringBody( string value )
541543
var pChars = pValue;
542544
var remainingCharsLength = value.Length;
543545
#endif // FEATURE_POINTER_CONVERSION
546+
var remainingBytesLength = encodedLength;
544547
var isCompleted = false;
545548
do
546549
{
547-
if ( !this.ShiftBufferIfNeeded( remainingCharsLength * sizeof( char ), ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
550+
if ( !this.ShiftBufferIfNeeded( remainingBytesLength, MaximumUtf8Length, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
548551
{
549-
this.ThrowEofExceptionForString( ( value.Length - remainingCharsLength ) * sizeof( char ) );
552+
this.ThrowEofExceptionForString( remainingBytesLength );
550553
}
551554

552555
int charsUsed, bytesUsed;
@@ -567,6 +570,7 @@ private unsafe void WriteStringBody( string value )
567570
charsOffset += charsUsed;
568571
#endif // FEATURE_POINTER_CONVERSION
569572
remainingCharsLength -= charsUsed;
573+
remainingBytesLength -= bytesUsed;
570574
currentBufferOffset += bytesUsed;
571575
} while ( remainingCharsLength > 0 );
572576
#if DEBUG

src/MsgPack/ByteArrayPackerWriter.TypedWrite.tt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ namespace MsgPack
5353

5454
partial class ByteArrayPackerWriter
5555
{
56+
private const int MaximumUtf8Length = 4;
57+
5658
<#
5759
foreach ( var isAsync in new [] { false, true } )
5860
{
@@ -86,7 +88,7 @@ namespace MsgPack
8688
var currentBufferOffset = this._currentBufferOffset;
8789
var currentBufferLimit = this._currentBufferLimit;
8890
var currentBufferIndex = this._currentBufferIndex;
89-
if ( !this.ShiftBufferIfNeeded( sizeof( <#= type #> ) + 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
91+
if ( !this.ShiftBufferIfNeeded( sizeof( <#= type #> ) + 1, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
9092
{
9193
this.ThrowEofException( sizeof( <#= type #> ) );
9294
}
@@ -128,7 +130,7 @@ namespace MsgPack
128130
#>
129131
private void WriteBytesSlow( <#= this.ToBitsType( type ) #> value, ref int currentBufferIndex, ref byte[] currentBuffer, ref int currentBufferOffset, ref int currentBufferLimit )
130132
{
131-
if ( !this.ShiftBufferIfNeeded( sizeof( <#= type #> ), ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
133+
if ( !this.ShiftBufferIfNeeded( sizeof( <#= type #> ), 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
132134
{
133135
this.ThrowEofException( sizeof( <#= type #> ) );
134136
}
@@ -145,7 +147,7 @@ namespace MsgPack
145147

146148
currentBufferOffset += currentWritten;
147149

148-
if ( !this.ShiftBufferIfNeeded( sizeof( <#= type #> ) - totalWritten, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
150+
if ( !this.ShiftBufferIfNeeded( sizeof( <#= type #> ) - totalWritten, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
149151
{
150152
this.ThrowEofException( sizeof( <#= type #> ) );
151153
}
@@ -186,7 +188,7 @@ namespace MsgPack
186188
}
187189
else
188190
{
189-
this.WriteStringBody( value );
191+
this.WriteStringBody( value, encodedLength );
190192
}
191193
<#
192194
} // if isAsync
@@ -227,7 +229,7 @@ namespace MsgPack
227229
}
228230

229231
#if !FEATURE_POINTER_CONVERSION
230-
private void WriteStringBody( string value )
232+
private void WriteStringBody( string value, int encodedLength )
231233
{
232234
var chars = BufferManager.NewCharBuffer( value.Length );
233235
int offset = 0;
@@ -236,16 +238,16 @@ namespace MsgPack
236238
{
237239
int copying = Math.Min( value.Length - offset, chars.Length );
238240
value.CopyTo( offset, chars, 0, copying );
239-
this.WriteStringBody( chars, copying );
241+
this.WriteStringBody( chars, copying, encodedLength );
240242
offset += copying;
241243
}
242244
}
243245

244-
private void WriteStringBody( char[] value, int remainingCharsLength )
246+
private void WriteStringBody( char[] value, int remainingCharsLength, int encodedLength )
245247
{
246248
var charsOffset = 0;
247249
#else
248-
private unsafe void WriteStringBody( string value )
250+
private unsafe void WriteStringBody( string value, int encodedLength )
249251
{
250252
fixed ( char* pValue = value )
251253
#endif // !FEATURE_POINTER_CONVERSION
@@ -259,12 +261,13 @@ namespace MsgPack
259261
var pChars = pValue;
260262
var remainingCharsLength = value.Length;
261263
#endif // FEATURE_POINTER_CONVERSION
264+
var remainingBytesLength = encodedLength;
262265
var isCompleted = false;
263266
do
264267
{
265-
if ( !this.ShiftBufferIfNeeded( remainingCharsLength * sizeof( char ), ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
268+
if ( !this.ShiftBufferIfNeeded( remainingBytesLength, MaximumUtf8Length, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
266269
{
267-
this.ThrowEofExceptionForString( ( value.Length - remainingCharsLength ) * sizeof( char ) );
270+
this.ThrowEofExceptionForString( remainingBytesLength );
268271
}
269272

270273
int charsUsed, bytesUsed;
@@ -285,6 +288,7 @@ namespace MsgPack
285288
charsOffset += charsUsed;
286289
#endif // FEATURE_POINTER_CONVERSION
287290
remainingCharsLength -= charsUsed;
291+
remainingBytesLength -= bytesUsed;
288292
currentBufferOffset += bytesUsed;
289293
} while ( remainingCharsLength > 0 );
290294
#if DEBUG

src/MsgPack/ByteArrayPackerWriter.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,17 @@ public IList<ArraySegment<byte>> GetBufferAsByteArray()
169169
return this._buffers;
170170
}
171171

172-
private bool ShiftBufferIfNeeded( int sizeHint, ref byte[] currentBuffer, ref int currentBufferOffset, ref int currentBufferLimit, ref int currentBufferIndex )
172+
private bool ShiftBufferIfNeeded( int sizeHint, int minimumSize, ref byte[] currentBuffer, ref int currentBufferOffset, ref int currentBufferLimit, ref int currentBufferIndex )
173173
{
174174
// Check current buffer is empty and whether more buffer is required.
175-
if ( currentBufferLimit == currentBufferOffset && sizeHint > 0 )
175+
if ( currentBufferLimit - currentBufferOffset < minimumSize && sizeHint > 0 )
176176
{
177177
// try shift to next buffer
178178
currentBufferIndex++;
179179
ArraySegment<byte> newBuffer;
180180
if ( this._buffers.Count == currentBufferIndex )
181181
{
182-
if ( !this._allocator.TryAllocate( this._buffers, sizeHint, ref currentBufferIndex, out newBuffer ) )
182+
if ( !this._allocator.TryAllocate( this._buffers, sizeHint, minimumSize, ref currentBufferIndex, out newBuffer ) )
183183
{
184184
return false;
185185
}
@@ -203,7 +203,7 @@ public override void WriteByte( byte value )
203203
var currentBufferOffset = this._currentBufferOffset;
204204
var currentBufferLimit = this._currentBufferLimit;
205205
var currentBufferIndex = this._currentBufferIndex;
206-
if ( !this.ShiftBufferIfNeeded( sizeof( byte ), ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
206+
if ( !this.ShiftBufferIfNeeded( sizeof( byte ), sizeof( byte ), ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
207207
{
208208
this.ThrowEofException( 1 );
209209
}
@@ -221,7 +221,7 @@ private void WriteBytes( byte[] value, int startIndex, int count )
221221
var currentBufferOffset = this._currentBufferOffset;
222222
var currentBufferLimit = this._currentBufferLimit;
223223
var currentBufferIndex = this._currentBufferIndex;
224-
if ( !this.ShiftBufferIfNeeded( count, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
224+
if ( !this.ShiftBufferIfNeeded( count, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
225225
{
226226
this.ThrowEofException( count );
227227
}
@@ -235,7 +235,7 @@ private void WriteBytes( byte[] value, int startIndex, int count )
235235
written += writes;
236236
currentBufferOffset += writes;
237237

238-
if ( !this.ShiftBufferIfNeeded( count - written, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
238+
if ( !this.ShiftBufferIfNeeded( count - written, 1, ref currentBuffer, ref currentBufferOffset, ref currentBufferLimit, ref currentBufferIndex ) )
239239
{
240240
this.ThrowEofException( count );
241241
}

0 commit comments

Comments
 (0)