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

Fetching from an encrypted max column after calling PDOstatement::nextRowset() returns some garage characters #580

Closed
yukiwongky opened this issue Oct 27, 2017 · 1 comment

Comments

@yukiwongky
Copy link
Contributor

After calling PDOstatement::nextRowset(), fetching from an encrypted max column returns some garbage characters. Following is a repro script:

<?php
try {
    $conn = new PDO("sqlsrv:server = $server; Database = $databaseName; ColumnEncryption = Enabled", $uid, $pwd);
    $tbname = "testNVarChar";
    $createSql = "CREATE TABLE $tbname
                  ([intCol] int ENCRYPTED WITH
                    (ENCRYPTION_TYPE = deterministic,
                     ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256',
                     COLUMN_ENCRYPTION_KEY = AEColumnKey),
                   [nVarCharCol] nvarchar(max) COLLATE Latin1_General_BIN2 ENCRYPTED WITH
                    (ENCRYPTION_TYPE = deterministic,
                     ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256',
                     COLUMN_ENCRYPTION_KEY = AEColumnKey))";
    $conn->exec($createSql);
    $intData = 1;
    $nvarcharData = "This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.";
    $insertSql = "INSERT INTO $tbname VALUES (?, ?)";
    $stmt = $conn->prepare($insertSql);
    $stmt->execute(array($intData, $nvarcharData));
    $selectSql = "SELECT intCol FROM $tbname; SELECT nVarCharCol FROM $tbname";
    $stmt = $conn->query($selectSql);

    $rowset = $stmt->fetch(PDO::FETCH_ASSOC);
    var_dump($rowset);
    $stmt->nextRowset();
    $rowset2 = $stmt->fetch(PDO::FETCH_ASSOC);
    var_dump($rowset2);

    $conn->exec("DROP TABLE $tbname");
    unset($stmt);
    unset($conn);
} catch (PDOException $e) {
    var_dump($e);
}
?>

Without column encryption, the proper data is returned. With column encryption however, the following is returned:

array(1) {
  [0]=>
  array(1) {
    ["intCol"]=>
    string(1) "1"
  }
}
array(1) {
  [0]=>
  array(1) {
    ["nVarCharCol"]=>
    string(440) "1 is is a really large string used to test certain large data types like xml data type. The length of this string is greater tha  辘ܵ움匜  윰ᓋ쳌쳌ᐆ       ă 슠刂  ű     a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters"
  }
}

The nvarchar string returned contains some weird characters.

@yitam
Copy link
Contributor

yitam commented Nov 22, 2017

Fixed in 5.1.2-preview

@yitam yitam closed this as completed Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants