sqlmapproject/sqlmap · error · InterfaceError

invalid TDS packet length (%d)

Error message

invalid TDS packet length (%d)

What it means

Error "invalid TDS packet length (%d)" thrown in sqlmapproject/sqlmap.

Source

Thrown at extra/dbwire/tds.py:74

        try:
            sock.sendall(header + chunk)
        except (socket.error, OSError) as ex:
            raise connection_lost(ex)
        packet_id += 1
        if last:
            break

def _read_message(sock):
    # reassemble a full TDS message across packets (EOM status bit marks the last). The packet length is a
    # 16-bit field, so bounding IT against _MAX_MESSAGE_LENGTH can never trigger - a hostile peer simply
    # never sets EOM and streams packets forever. Bound the accumulated message instead, and collect the
    # chunks in a list so reassembly stays linear rather than re-copying a growing immutable buffer.
    chunks, total = [], 0
    while True:
        header = recvn(sock, 8)
        mtype, status, length = struct.unpack(">BBH", header[:4])
        if length < 8:
            raise InterfaceError("invalid TDS packet length (%d)" % length)
        total += length - 8
        if total > _MAX_MESSAGE_LENGTH:
            raise InterfaceError("TDS message exceeds the maximum allowed length (%d bytes)" % _MAX_MESSAGE_LENGTH)
        chunks.append(recvn(sock, length - 8))
        if status & _STATUS_EOM:
            break
    return b"".join(chunks)

# ---- PRELOGIN ----------------------------------------------------------------------------------------

def _prelogin(sock):
    ver = struct.pack(">IH", 0x11000000, 0)
    enc = b"\x02"  # ENCRYPT_NOT_SUP
    tokens = b"\x00" + struct.pack(">HH", 11, len(ver))
    tokens += b"\x01" + struct.pack(">HH", 11 + len(ver), len(enc))
    tokens += b"\xff"
    _send_message(sock, _PKT_PRELOGIN, tokens + ver + enc)
    body = _read_message(sock)

View on GitHub (pinned to 0a35b20e39)

When it happens

Trigger: Thrown at extra/dbwire/tds.py:74 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sqlmapproject/sqlmap@0a35b20e39 (2026-08-26). Data as JSON: /api/errors/6872e8902714a738. Report an issue: GitHub.