Skip to content

Fix SpiAdapter.Read buffer length mismatch in Mcp23xxx TransferFullDuplex#2492

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-argument-exception-buffers
Draft

Fix SpiAdapter.Read buffer length mismatch in Mcp23xxx TransferFullDuplex#2492
Copilot wants to merge 2 commits intomainfrom
copilot/fix-argument-exception-buffers

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 9, 2026

SpiAdapter.Read() passes a 2-byte writeBuffer and a (buffer.Length + 2)-byte readBuffer to TransferFullDuplex, which requires equal-length buffers. This throws ArgumentException on any real SPI device (e.g., UnixSpiDevice).

  • SpiAdapter.cs: Allocate writeBuffer at the same length as readBuffer. OpCode and register address occupy the first 2 bytes; remaining bytes are zero-filled don't-care padding per standard SPI full-duplex read semantics.
  • Mcp23xxxTest.cs: Fix SpiDeviceMock.TransferFullDuplex to only forward the 2-byte command prefix to Write(), preventing the don't-care padding from overwriting mock register state.
// Before: writeBuffer is 2 bytes, readBuffer is buffer.Length + 2 — mismatch
Span<byte> writeBuffer = stackalloc byte[] { opCode, registerAddress };
Span<byte> readBuffer = stackalloc byte[buffer.Length + 2];

// After: both buffers are buffer.Length + 2
Span<byte> writeBuffer = stackalloc byte[fullLength];
writeBuffer[0] = opCode;
writeBuffer[1] = registerAddress;
Span<byte> readBuffer = stackalloc byte[fullLength];

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 1oavsblobprodcus350.vsblob.vsassets.io
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/ArduinoCsCompiler/ArduinoCsCompiler.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • 1s1vsblobprodcus386.vsblob.vsassets.io
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/src/System.Device.Gpio/System.Device.Gpio.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/DevicesApiTester/DeviceApiTester.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/ArduinoCsCompiler/ArduinoCsCompiler.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • 2kmvsblobprodcus39.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/devices/Mcp23xxx/Mcp23xxx.csproj (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/samples/samples.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/src/System.Device.Gpio/System.Device.Gpio.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • 37cvsblobprodcus359.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/devices/Mcp23xxx/Mcp23xxx.csproj (dns block)
  • 4m6vsblobprodcus384.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/devices/Mcp23xxx/Mcp23xxx.csproj (dns block)
  • 4vyvsblobprodcus361.vsblob.vsassets.io
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/samples/samples.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/src/System.Device.Gpio/System.Device.Gpio.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/ArduinoCsCompiler/ArduinoCsCompiler.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • 6s7vsblobprodcus313.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/devices/Mcp23xxx/Mcp23xxx.csproj (dns block)
  • 80zvsblobprodcus35.vsblob.vsassets.io
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/samples/samples.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/src/System.Device.Gpio/System.Device.Gpio.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/DevicesApiTester/DeviceApiTester.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • bcnvsblobprodcus378.vsblob.vsassets.io
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/src/devices/BuildHat/BuildHat.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • fdpvsblobprodcus345.vsblob.vsassets.io
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/ArduinoCsCompiler/ArduinoCsCompiler.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/src/devices/Ccs811/Ccs811.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/src/devices/Scd4x/Scd4x.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • gbsvsblobprodcus365.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/devices/Mcp23xxx/Mcp23xxx.csproj (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/ArduinoCsCompiler/ArduinoCsCompiler.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/src/devices/Ccs811/Ccs811.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • gervsblobprodcus329.vsblob.vsassets.io
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/DevicesApiTester/DeviceApiTester.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/ArduinoCsCompiler/ArduinoCsCompiler.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • ibzvsblobprodcus369.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/devices/Mcp23xxx/Mcp23xxx.csproj (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/samples/samples.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/GenerateDocFxStructure/GenerateDocFxStructure.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • josvsblobprodcus372.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/devices/Mcp23xxx/Mcp23xxx.csproj (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/devices/Mcp23xxx/Mcp23xxx.csproj (dns block)
  • o3svsblobprodcus318.vsblob.vsassets.io
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/samples/samples.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/src/System.Device.Gpio/System.Device.Gpio.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/ArduinoCsCompiler/ArduinoCsCompiler.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • ofvvsblobprodcus315.vsblob.vsassets.io
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/src/System.Device.Gpio/System.Device.Gpio.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/DevicesApiTester/DeviceApiTester.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/ArduinoCsCompiler/ArduinoCsCompiler.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • p2ovsblobprodcus312.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/devices/Mcp23xxx/Mcp23xxx.csproj (dns block)
  • pkvvsblobprodcus321.vsblob.vsassets.io
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/samples/samples.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/src/System.Device.Gpio/System.Device.Gpio.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/tools/ArduinoCsCompiler/ArduinoCsCompiler.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • s4uvsblobprodcus326.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/devices/Mcp23xxx/Mcp23xxx.csproj (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/samples/samples.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/iot/iot/src/System.Device.Gpio/System.Device.Gpio.sln --packages /tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-db3f4ba25dde505c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
  • sc4vsblobprodcus331.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/devices/Mcp23xxx/Mcp23xxx.csproj (dns block)
  • securitytools.pkgs.visualstudio.com
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)
  • tphvsblobprodcus375.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/devices/Mcp23xxx/Mcp23xxx.csproj (dns block)
  • yluvsblobprodcus367.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/devices/Mcp23xxx/Mcp23xxx.csproj (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

TransferFullDuplex requires writeBuffer and readBuffer to have the same
length. The Read method was creating a 2-byte writeBuffer and a
(buffer.Length + 2)-byte readBuffer, causing ArgumentException on real
SPI devices.

Fix: allocate writeBuffer with the same size as readBuffer, placing
OpCode and register address in the first two bytes (remaining bytes are
don't-care for the SPI read operation).

Also fix the test mock's TransferFullDuplex to only pass command bytes
to Write, preventing don't-care padding from corrupting register data.

Agent-Logs-Url: https://github.com/dotnet/iot/sessions/7c410060-a096-49b1-8cfa-348f86e1f77b

Co-authored-by: krwq <660048+krwq@users.noreply.github.com>
@dotnet-policy-service dotnet-policy-service bot added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Apr 9, 2026
Copilot AI changed the title [WIP] Fix System.ArgumentException for buffer length mismatch Fix SpiAdapter.Read buffer length mismatch in Mcp23xxx TransferFullDuplex Apr 9, 2026
Copilot finished work on behalf of krwq April 9, 2026 16:00
Copilot AI requested a review from krwq April 9, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.ArgumentException: Parameters 'writeBuffer' and 'readBuffer' must have the same length

2 participants