{"record":{"id":"61f3f247122af156","repo":"apache/cassandra","slug":"invalid-paging-state","errorCode":null,"errorMessage":"Invalid paging state.","messagePattern":"Invalid paging state\\.","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/DescribeStatement.java","lineNumber":218,"sourceCode":"    protected abstract List<ColumnSpecification> metadata(ClientState state);\n\n    private PagingState getPagingState(long nextPageOffset, UUID schemaVersion)\n    {\n        try (DataOutputBuffer out = new DataOutputBuffer())\n        {\n            out.writeShort(PAGING_STATE_VERSION);\n            out.writeUTF(FBUtilities.getReleaseVersionString());\n            out.write(UUIDGen.decompose(schemaVersion));\n            out.writeLong(nextPageOffset);\n\n            return new PagingState(out.asNewBuffer(),\n                                   null,\n                                   Integer.MAX_VALUE,\n                                   Integer.MAX_VALUE);\n        }\n        catch (IOException e)\n        {\n            throw new InvalidRequestException(\"Invalid paging state.\", e);\n        }\n    }\n\n    private long getOffset(PagingState pagingState, UUID schemaVersion)\n    {\n        if (pagingState == null)\n            return 0L;\n\n        try (DataInputBuffer in = new DataInputBuffer(pagingState.partitionKey, false))\n        {\n            checkTrue(in.readShort() == PAGING_STATE_VERSION, \"Incompatible paging state\");\n\n            final String pagingStateServerVersion = in.readUTF();\n            final String releaseVersion = FBUtilities.getReleaseVersionString();\n            checkTrue(pagingStateServerVersion.equals(releaseVersion),\n                      \"The server version of the paging state %s is different from the one of the server %s\",\n                      pagingStateServerVersion,\n                      releaseVersion);","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/DescribeStatement.java#L200-L236","documentation":"DescribeStatement (DESCRIBE output for schema/tables/etc.) deserializes the client-supplied PagingState blob to continue pagination; if the blob cannot be decoded (DataInputStream/ByteArrayInputStream I/O failure), it throws InvalidRequestException('Invalid paging state.').","triggerScenarios":"Passing a PagingState produced by a different statement/version, a truncated or hand-crafted byte buffer, or one whose internal format doesn't match the current reader, causing an IOException during getPagingState's readUTF/readInt sequence.","commonSituations":"Client code persisting paging state across process restarts with a different Cassandra version; copying pagingState bytes between different DESCRIBE commands; truncating the byte buffer; driver-level manipulation of the state blob.","solutions":["Restart pagination from the beginning (null paging state) instead of reusing an opaque/incompatible state.","Only pass PagingState values returned by the exact same statement type on a compatible Cassandra version.","Don't mutate, truncate, or base64-round-trip the paging state bytes incorrectly; if persisting, store the raw bytes verbatim.","Catch InvalidRequestException and fall back to a fresh first-page query."],"exampleFix":"// before\nstate = oldStateFromOtherCommand; // incompatible blob\nresult = session.execute(describeStatement.setPagingState(state));\n// after\ntry {\n    result = session.execute(describeStatement.setPagingState(savedState));\n} catch (InvalidRequestException e) {\n    result = session.execute(describeStatement); // restart from page 1\n}","handlingStrategy":"try-catch","validationCode":"// only reuse paging states obtained from the same statement type/version\nif (savedState == null || savedState.remaining <= 0 || !savedState.sourceCommand.equals(\"DESCRIBE\")) savedState = null;","typeGuard":"boolean isValidPagingState(byte[] b) { return b != null && b.length > 0 && b.length <= 65535; }","tryCatchPattern":"try { rs = session.execute(stmt.setPagingState(savedState)); } catch (InvalidRequestException e) { if (e.getMessage().equals(\"Invalid paging state.\")) { rs = session.execute(stmt); /* restart from first page */ } else throw e; }","preventionTips":["Never hand-build or truncate PagingState bytes","Persist paging state as exact raw bytes (lossless encoding)","Restart pagination from scratch after client/server upgrades"],"tags":["pagination","invalid-request","serialization"],"backgroundTag":"invalid-argument-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}