Skip to content

Commit

Permalink
Add failing test; fix BufferedStreamSource bug where .Position is que…
Browse files Browse the repository at this point in the history
…ried on non-seekable streams, causing a failure.
  • Loading branch information
lilith committed Mar 9, 2024
1 parent 425dc94 commit d0b5fdc
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Imageflow/Fluent/BufferedStreamSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public sealed class BufferedStreamSource : IAsyncMemorySource, IMemorySource
{
private BufferedStreamSource(Stream stream, bool disposeUnderlying, bool seekToStart)
{
if (stream.Position != 0 && !stream.CanSeek && seekToStart)
if (!stream.CanSeek && seekToStart)
{
throw new ArgumentException("Stream must be seekable if seekToStart is true");
}
Expand Down
62 changes: 62 additions & 0 deletions tests/Imageflow.Test/NonSeekableReadStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
namespace Imageflow.Test;

using System;
using System.IO;

public class NonSeekableReadStream : Stream
{
private byte[] data;
private long position = 0; // Current position within the data

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Member 'position' is explicitly initialized to its default value (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1805)

public NonSeekableReadStream(byte[] dataSource)
{
data = dataSource ?? throw new ArgumentNullException(nameof(dataSource));
}

public override bool CanRead => true;
public override bool CanSeek => false;
public override bool CanWrite => false;

public override long Length => data.Length;

public override long Position
{
get => throw new NotSupportedException("Seeking not supported.");
set => throw new NotSupportedException("Seeking not supported.");
}

public override void Flush()
{
// No-op for read-only stream
}

public override int Read(byte[] buffer, int offset, int count)
{
if (buffer == null) throw new ArgumentNullException(nameof(buffer));

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)

Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1510)
if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException("offset or count is negative.");

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-11.0)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)

Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

Method Read passes 'offset or count is negative.' as the paramName argument to a ArgumentOutOfRangeException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208)
if (buffer.Length - offset < count) throw new ArgumentException("The sum of offset and count is greater than the buffer length.");

int available = data.Length - (int)position;
if (available <= 0) return 0; // End of stream

int toCopy = Math.Min(available, count);
Array.Copy(data, position, buffer, offset, toCopy);
position += toCopy;
return toCopy;
}

public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException("Seeking not supported.");
}

public override void SetLength(long value)
{
throw new NotSupportedException("Setting length not supported.");
}

public override void Write(byte[] buffer, int offset, int count)
{
throw new NotSupportedException("Writing not supported.");
}
}
6 changes: 3 additions & 3 deletions tests/Imageflow.Test/TestApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public async Task TestBuildCommandStringWithStreamsAndWatermarksLegacy()
var stream1 = new BufferedStream(new MemoryStream(imageBytes));
Assert.Equal(137, stream1.ReadByte());
stream1.Seek(0, SeekOrigin.Begin);
var stream2 = new BufferedStream(new MemoryStream(imageBytes));
var stream2 = new NonSeekableReadStream(imageBytes);
var stream3 = new BufferedStream(new MemoryStream(imageBytes));
using (var b = new ImageJob())
{
Expand Down Expand Up @@ -361,12 +361,12 @@ public async Task TestBuildCommandStringWithStreamsAndWatermarks()
var stream1 = new BufferedStream(new MemoryStream(imageBytes));
Assert.Equal(137, stream1.ReadByte());
stream1.Seek(0, SeekOrigin.Begin);
var stream2 = new BufferedStream(new MemoryStream(imageBytes));
var stream2 = new NonSeekableReadStream(imageBytes);
var stream3 = new BufferedStream(new MemoryStream(imageBytes));
using var b = new ImageJob();
var watermarks = new List<InputWatermark>();
watermarks.Add(new InputWatermark(BufferedStreamSource.UseEntireStreamAndDisposeWithSource(stream1), new WatermarkOptions()));
watermarks.Add(new InputWatermark(BufferedStreamSource.UseEntireStreamAndDisposeWithSource(stream2), new WatermarkOptions().SetGravity(new ConstraintGravity(100, 100))));
watermarks.Add(new InputWatermark(BufferedStreamSource.UseStreamRemainderAndDisposeWithSource(stream2), new WatermarkOptions().SetGravity(new ConstraintGravity(100, 100))));

var r = await b.BuildCommandString(
BufferedStreamSource.UseEntireStreamAndDisposeWithSource(stream3),
Expand Down

0 comments on commit d0b5fdc

Please sign in to comment.