Skip to content

[s390x] System.DirectoryServices.Protocols: OverflowException in LdapSessionOptions.ProtocolVersion on Big Endian #112390

@medhatiwari

Description

@medhatiwari

Description

On Big Endian architectures (s390x), the test:
The LdapSessionOptions.ProtocolVersion property in System.DirectoryServices.Protocols throws an OverflowException on Big Endian architectures (e.g., s390x).

This happens because IntPtr.ToInt32() assumes Little Endian memory layout, but on Big Endian, the upper 32 bits are nonzero, leading to overflow.

Reproduction Steps

Environment

  • Architecture: s390x (Big Endian)
  • OS: Linux (RHEL 9.4, Ubuntu)
  • .NET Version: 10.0.100-alpha.1

Steps to Reproduce

  1. Run:
    dotnet test --filter "FullyQualifiedName=System.DirectoryServices.Protocols.Tests.LdapSessionOptionsTests.ProtocolVersion_Set_GetReturnsExpected"
    
    

The test fails with an OverflowException

Expected behavior

  • ProtocolVersion should correctly retrieve and set the integer version of LDAP across all architectures.
  • On Big Endian (s390x), it should properly interpret the integer value stored in the pointer instead of causing an OverflowException.

Actual behavior

  • The test fails with an OverflowException due to incorrect conversion of the IntPtr on Big Endian.

This happens because:

  • GetPtrValueHelper(LdapOption.LDAP_OPT_VERSION) returns an IntPtr.
  • ToInt32() incorrectly interprets it without adjusting for endianness.
  • This works fine on Little Endian (x86, ARM64), but fails on Big Endian (s390x).

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

  • This bug affects Big Endian architectures (s390x).
  • The error is not reproducible on x86/x64 due to their Little Endian layout.
  • Fixing this ensures that LDAP-based authentication works correctly on IBM mainframes and other Big Endian platforms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions