Repository navigation
fix: surface malformed handshake packets instead of trapping - #5
Merged
Merged
Conversation
Decoding a server packet during the connection handshake could hit a Swift runtime trap on the NIO channel thread, which crashes the whole process and cannot be caught by the connection's error handling. - ServerSidePiggyback.decode skipped fields with the non-throwing moveReaderIndex(forwardBy:), so a short sync/sessRet piggyback (sent by Oracle 12c+ during normal session setup) trapped past the buffer end. Use throwingMoveReaderIndex so a short packet surfaces a decoding error. - OracleChannelHandler treated every server-side piggyback as a fatalError. Handle it as informational (sync, sessRet, ...) and keep waiting. - Protocol.decode computed the charset index with UInt8 arithmetic (which overflows) and unguarded fdo[] subscripts. Compute in Int, bounds-check the fdo buffer, and widen before shifting so the national charset id is correct. - BackendError.decode wrote batch error offsets/messages past the batch array when the server reported more than the code count. Guard the index. - The UB/SB readers and skipUB hit preconditionFailure/fatalError on out-of-range or short length prefixes. Return nil or throw instead. Adds OracleNIOTests coverage for each path.
datlechin
force-pushed
the
fix/server-side-piggyback-decode-trap
branch
from
June 15, 2026 09:48
b2a5e27 to
8b39c44
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Decoding a server packet during the connection handshake could hit a Swift runtime trap (
brk #1) on the NIO channel thread. That crashes the whole process and cannot be caught by the connection's error handling, so the app dies on connect with no surfaced error.Proven by symbolicating a crashed
OracleDriverbuild (TablePro #1683, UUID-matched): the trap was inServerSidePiggyback.decode, the.synccase, at a non-throwingmoveReaderIndex(forwardBy:). Oracle 12c+ sends a.syncserver-side piggyback during normal session setup; on some servers the packet is shorter than the decoder's fixed skips, so the move runs past the buffer end and traps. It is server/version specific, which is why only some users hit it.Changes
moveReaderIndex(forwardBy:)withthrowingMoveReaderIndex, so a shortsync/sessRet/ltxID/acReplayContextpacket surfaces anOraclePartialDecodingErrorinstead of trapping.fatalError(the comment claimed it only happens with LOBs and "should never happen"). It is informational session metadata; log it and keep waiting. This is a second crash on the same path.ix = 6 + fdo[5] + fdo[6]usedUInt8arithmetic (overflows) and unguardedfdo[]subscripts. Compute inInt, bounds-check the fdo buffer, and widen before shifting so the national charset id is computed correctly.preconditionFailure/fatalErroron out-of-range or short length prefixes. Returnnilor throw instead.Tests
ServerSidePiggybackTests: a truncatedsync/sessRetthrows instead of trapping; a well-formedsyncdecodes; a short piggyback inside a data packet surfaces an error.ProtocolMessageTests: a short FDO throws; a well-formed FDO computes the full 16-bit charset id.BackendErrorTests: more batch offsets than codes does not trap.ByteBufferExtensionTests: UB/SB readers return nil andthrowingSkipUBthrows on out-of-range/short length.Local
swift testis blocked here by an Xcode 27 beta toolchain issue in a dependency; CI validates the full build and tests.