Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataclassification sensitivity max index fix #1847

Merged
merged 2 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/main/java/com/microsoft/sqlserver/jdbc/StreamColumns.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ final class StreamColumns extends StreamPacket {

private boolean sensitivityRankSupported = false;

// SensitivityLabelIndex and InformationTypeIndex as defined in the TDS spec have a max of USHORT_MAX
private static final int DATACLASSIFICATION_INDEX_MAX = 65535;
tkyc marked this conversation as resolved.
Show resolved Hide resolved

/* Returns the CekTable */
CekTable getCekTable() {
return cekTable;
Expand Down Expand Up @@ -285,7 +288,9 @@ SensitivityClassification processDataClassification(TDSReader tdsReader) throws
// get the label index and then lookup label to use for source
int sensitivityLabelIndex = tdsReader.readUnsignedShort();
Label label = null;
if (sensitivityLabelIndex != Integer.MAX_VALUE) {

// If sensitivity label index is equal to USHORT_MAX eg. 65535 then there is no sensitivity label
if (sensitivityLabelIndex != DATACLASSIFICATION_INDEX_MAX) {
if (sensitivityLabelIndex >= sensitivityLabels.size()) {
tdsReader.throwInvalidTDS();
}
Expand All @@ -294,7 +299,9 @@ SensitivityClassification processDataClassification(TDSReader tdsReader) throws
// get the information type index and then lookup information type to use for source
int informationTypeIndex = tdsReader.readUnsignedShort();
InformationType informationType = null;
if (informationTypeIndex != Integer.MAX_VALUE) {

// If information type index is equal to USHORT_MAX eg. 65535 then there is no information type
if (informationTypeIndex != DATACLASSIFICATION_INDEX_MAX) {
if (informationTypeIndex >= informationTypes.size()) {}
informationType = informationTypes.get(informationTypeIndex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class DataClassificationTest extends AbstractTest {
.escapeIdentifier(RandomUtil.getIdentifier("DataClassification"));
private static final String tableName1 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("SelectMethodCursor"));
private static final String tableName2 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("USHORT_MAX"));
private static final String addSensitivitySql = "ADD SENSITIVITY CLASSIFICATION TO %s.%s WITH (LABEL='PII', LABEL_ID='L1', INFORMATION_TYPE='%s', INFORMATION_TYPE_ID='%s'%s)";
private static final String sensitivityRankSql = ", RANK=%s";

Expand All @@ -52,6 +54,34 @@ public static void setupTests() throws Exception {
setConnection();
}

@Test
@Tag(Constants.xAzureSQLDW)
@Tag(Constants.xSQLv11)
@Tag(Constants.xSQLv12)
@Tag(Constants.xSQLv14)
public void testInformationTypeSensitivityLabelIndexMax() throws Exception {
String createTable = "create table " + tableName2 + " (col1 varchar(200), col2 varchar(200), col3 varchar(200))";
String sensitivityClassification = "ADD SENSITIVITY CLASSIFICATION TO %s.%s WITH (LABEL='PII')";
String query = "select * from " + tableName2;

try (SQLServerConnection conn = PrepUtil.getConnection(connectionString)) {
// Create table
try (Statement stmt = conn.createStatement()) {
stmt.execute(createTable);
}

// Add sensitivity classification
try (Statement stmt = conn.createStatement()) {
stmt.execute(String.format(sensitivityClassification, tableName2, "col1"));
}

// Execute query
try (Statement stmt = conn.createStatement()) {
stmt.execute(query);
}
}
}

@Test
@Tag(Constants.xAzureSQLDW)
@Tag(Constants.xSQLv11)
Expand Down