Skip to content

Commit

Permalink
fix: throw an exception when MemoryStream instance has an empty backi…
Browse files Browse the repository at this point in the history
…ng array
  • Loading branch information
kessplas authored Jan 31, 2024
2 parents 3c36f7a + e89e2fd commit 550c714
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,17 @@ public static System.IO.MemoryStream FromDafny_N6_smithy__N3_api__S4_Blob(Dafny.

public static Dafny.ISequence<byte> ToDafny_N6_smithy__N3_api__S4_Blob(System.IO.MemoryStream value)
{
// BEGIN MANUAL EDIT
// It is possible for a MemoryStream to be implemented by another stream,
// which may or may not be backed with an array.
// If the array is empty, but the stream isn't, then
// the backing stream cannot be treated as a MemoryStream
// for purposes of type conversion through ToArray().
if (value.ToArray().Length == 0 && value.Length > 0)
{
throw new System.ArgumentException("Fatal Error: MemoryStream instance not backed by an array!");
}
// END MANUAL EDIT
return Dafny.Sequence<byte>.FromArray(value.ToArray());
}

Expand Down

0 comments on commit 550c714

Please sign in to comment.