diff --git a/main/DDF/EscherBSERecord.cs b/main/DDF/EscherBSERecord.cs index c355603e4..da30605e5 100644 --- a/main/DDF/EscherBSERecord.cs +++ b/main/DDF/EscherBSERecord.cs @@ -349,7 +349,7 @@ public override String ToString() { HexDump.Dump(this._remainingData, 0, b, 0); //extraData = b.ToString(); - extraData = Encoding.UTF8.GetString(b.ToArray()); + extraData = Encoding.UTF8.GetString(b.GetBuffer(), 0, (int)b.Length); } catch (Exception e) { diff --git a/main/DDF/EscherBlipWMFRecord.cs b/main/DDF/EscherBlipWMFRecord.cs index c75b07504..a528a97a5 100644 --- a/main/DDF/EscherBlipWMFRecord.cs +++ b/main/DDF/EscherBlipWMFRecord.cs @@ -287,7 +287,7 @@ public override String ToString() { HexDump.Dump(this.field_12_data, 0, b, 0); //extraData = b.ToString(); - extraData = Encoding.UTF8.GetString(b.ToArray()); + extraData = Encoding.UTF8.GetString(b.GetBuffer(), 0, (int)b.Length); } catch (Exception e) { diff --git a/main/HPSF/MutableSection.cs b/main/HPSF/MutableSection.cs index 23a74417f..2356eee06 100644 --- a/main/HPSF/MutableSection.cs +++ b/main/HPSF/MutableSection.cs @@ -426,23 +426,25 @@ public int Write(Stream out1) propertyListStream.Flush(); /* Write the section: */ - byte[] pb1 = propertyListStream.ToArray(); - byte[] pb2 = propertyStream.ToArray(); + byte[] pb1 = propertyListStream.GetBuffer(); + byte[] pb2 = propertyStream.GetBuffer(); + int pb1Length = (int)propertyListStream.Length; + int pb2Length = (int)propertyStream.Length; /* Write the section's Length: */ TypeWriter.WriteToStream(out1, LittleEndianConsts.INT_SIZE * 2 + - pb1.Length + pb2.Length); + pb1Length + pb2Length); /* Write the section's number of properties: */ TypeWriter.WriteToStream(out1, PropertyCount); /* Write the property list: */ - out1.Write(pb1, 0, pb1.Length); + out1.Write(pb1, 0, pb1Length); /* Write the properties: */ - out1.Write(pb2, 0, pb2.Length); + out1.Write(pb2, 0, pb2Length); - int streamLength = LittleEndianConsts.INT_SIZE * 2 + pb1.Length + pb2.Length; + int streamLength = LittleEndianConsts.INT_SIZE * 2 + pb1Length + pb2Length; return streamLength; } } diff --git a/main/HSSF/Record/Crypto/Biff8EncryptionKey.cs b/main/HSSF/Record/Crypto/Biff8EncryptionKey.cs index 13631e065..45fc9fb03 100644 --- a/main/HSSF/Record/Crypto/Biff8EncryptionKey.cs +++ b/main/HSSF/Record/Crypto/Biff8EncryptionKey.cs @@ -138,10 +138,9 @@ internal RC4 CreateRC4(int keyBlockNo) using (MemoryStream baos = RecyclableMemory.GetStream(4)) { new LittleEndianOutputStream(baos).WriteInt(keyBlockNo); - byte[] baosToArray = baos.ToArray(); - byte[] data = new byte[baosToArray.Length + _keyDigest.Length]; + byte[] data = new byte[(int)baos.Length + _keyDigest.Length]; Array.Copy(_keyDigest, 0, data, 0, _keyDigest.Length); - Array.Copy(baosToArray, 0, data, _keyDigest.Length, baosToArray.Length); + Array.Copy(baos.GetBuffer(), 0, data, _keyDigest.Length, (int)baos.Length); byte[] digest = md5.ComputeHash(data); return new RC4(digest); diff --git a/main/POIFS/Storage/HeaderBlockWriter.cs b/main/POIFS/Storage/HeaderBlockWriter.cs index ccf741af1..4fe1e433f 100644 --- a/main/POIFS/Storage/HeaderBlockWriter.cs +++ b/main/POIFS/Storage/HeaderBlockWriter.cs @@ -169,7 +169,7 @@ public void WriteBlock(ByteBuffer block) { _header_block.WriteData(ms); - block.Write(ms.ToArray()); + block.Write(ms.GetBuffer(), 0, (int)ms.Length); } } @@ -180,8 +180,7 @@ public void WriteBlock(byte[] block) { _header_block.WriteData(ms); - byte[] temp = ms.ToArray(); - Array.Copy(temp, 0, block, 0, temp.Length); + Array.Copy(ms.GetBuffer(), 0, block, 0, (int)ms.Length); } } } diff --git a/main/Util/HexDump.cs b/main/Util/HexDump.cs index 08790bb23..5836eded7 100644 --- a/main/Util/HexDump.cs +++ b/main/Util/HexDump.cs @@ -206,8 +206,7 @@ public static void Dump(Stream inStream, int start, int bytesToDump) stream.WriteByte((byte)c); } } - byte[] data = stream.ToArray(); - Dump(data, 0L, null, start, data.Length); + Dump(stream.GetBuffer(), 0L, null, start, (int)stream.Length); } } @@ -318,8 +317,7 @@ public static void Dump(Stream in1, Stream out1, int start, int bytesToDump ) } } - byte[] data = buf.ToArray(); - Dump(data, 0, out1, start, data.Length); + Dump(buf.GetBuffer(), 0, out1, start, (int)buf.Length); } /// diff --git a/ooxml/POIFS/Crypt/Agile/AgileEncryptor.cs b/ooxml/POIFS/Crypt/Agile/AgileEncryptor.cs index a4166ebc8..31344d65f 100644 --- a/ooxml/POIFS/Crypt/Agile/AgileEncryptor.cs +++ b/ooxml/POIFS/Crypt/Agile/AgileEncryptor.cs @@ -320,7 +320,7 @@ protected void marshallEncryptionDocument(EncryptionDocument ed, LittleEndianByt byte[] buf = Encoding.UTF8.GetBytes("\r\n"); bos.Write(buf, 0, buf.Length); ed.Save(bos); - os.Write(bos.ToArray()); + os.Write(bos.GetBuffer(), 0, (int)bos.Length); } catch (IOException e) { throw new EncryptedDocumentException("error marshalling encryption info document", e); } diff --git a/openxml4Net/OPC/OPCPackage.cs b/openxml4Net/OPC/OPCPackage.cs index 6443d72cc..cd8b39019 100644 --- a/openxml4Net/OPC/OPCPackage.cs +++ b/openxml4Net/OPC/OPCPackage.cs @@ -1023,7 +1023,7 @@ public PackagePart CreatePart(PackagePartName partName, String contentType, return null; } - partOutput.Write(content.ToArray(), 0, (int)content.Length); + partOutput.Write(content.TryGetBuffer(out var buf) ? buf.Array : content.ToArray(), 0, (int)content.Length); partOutput.Close(); }