Skip to content

Commit a3e880c

Browse files
committed
Pad and Fill are used for reading and also writing (though same data) and that *might* cause some race conditions. (DNET-803)
1 parent eaa9353 commit a3e880c

File tree

1 file changed

+19
-39
lines changed
  • Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed

1 file changed

+19
-39
lines changed

Provider/src/FirebirdSql.Data.FirebirdClient/Client/Managed/XdrStream.cs

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,39 +38,6 @@ internal class XdrStream : Stream
3838

3939
#endregion
4040

41-
#region Static Fields
42-
43-
private static byte[] fill;
44-
private static byte[] pad;
45-
46-
#endregion
47-
48-
#region Static Properties
49-
50-
internal static byte[] Fill
51-
{
52-
get
53-
{
54-
if (fill == null)
55-
{
56-
fill = new byte[32767];
57-
for (int i = 0; i < fill.Length; i++)
58-
{
59-
fill[i] = 32;
60-
}
61-
}
62-
63-
return fill;
64-
}
65-
}
66-
67-
private static byte[] Pad
68-
{
69-
get { return pad ?? (pad = new byte[] { 0, 0, 0, 0 }); }
70-
}
71-
72-
#endregion
73-
7441
#region Fields
7542

7643
private Stream _innerStream;
@@ -447,7 +414,8 @@ public byte[] ReadOpaque(int length)
447414
var padLength = ((4 - length) & 3);
448415
if (padLength > 0)
449416
{
450-
Read(Pad, 0, padLength);
417+
var dummy = new byte[padLength];
418+
Read(dummy, 0, padLength);
451419
}
452420
return buffer;
453421
}
@@ -621,8 +589,8 @@ public void WriteOpaque(byte[] buffer, int length)
621589
if (buffer != null && length > 0)
622590
{
623591
Write(buffer, 0, buffer.Length);
624-
Write(Fill, 0, length - buffer.Length);
625-
Write(Pad, 0, ((4 - length) & 3));
592+
WriteFill(length - buffer.Length);
593+
WritePad((4 - length) & 3);
626594
}
627595
}
628596

@@ -637,7 +605,7 @@ public void WriteBuffer(byte[] buffer, int length)
637605
if (buffer != null && length > 0)
638606
{
639607
Write(buffer, 0, length);
640-
Write(Pad, 0, ((4 - length) & 3));
608+
WritePad((4 - length) & 3);
641609
}
642610
}
643611

@@ -651,7 +619,7 @@ public void WriteBlobBuffer(byte[] buffer)
651619
WriteByte((byte)((length >> 0) & 0xff));
652620
WriteByte((byte)((length >> 8) & 0xff));
653621
Write(buffer, 0, length);
654-
Write(Pad, 0, ((4 - length + 2) & 3));
622+
WritePad((4 - length + 2) & 3);
655623
}
656624

657625
public void WriteTyped(int type, byte[] buffer)
@@ -670,7 +638,7 @@ public void WriteTyped(int type, byte[] buffer)
670638
WriteByte((byte)type);
671639
Write(buffer, 0, buffer.Length);
672640
}
673-
Write(Pad, 0, ((4 - length) & 3));
641+
WritePad((4 - length) & 3);
674642
}
675643

676644
public void Write(string value)
@@ -779,6 +747,18 @@ private void EnsureReadable()
779747
throw new InvalidOperationException("Read operations are not allowed by this stream.");
780748
}
781749

750+
private readonly static byte[] PadArray = new byte[] { 0, 0, 0, 0 };
751+
private void WritePad(int length)
752+
{
753+
Write(PadArray, 0, length);
754+
}
755+
756+
private readonly static byte[] FillArray = Enumerable.Repeat((byte)32, 32767).ToArray();
757+
private void WriteFill(int length)
758+
{
759+
Write(FillArray, 0, length);
760+
}
761+
782762
#endregion
783763
}
784764
}

0 commit comments

Comments
 (0)