bug(bq_driver): SQLDriverConnectW corrupts/fails to NUL-terminate outConnectionString (breaks Microsoft Excel / iODBC on macOS)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Start in google/cloud/odbc/bq_driver/odbc_api.cc at SQLDriverConnectW and compare its output handling with SQLBrowseConnectW. Check the wire buffer helpers in odbc_type_utils.h and the ODBC truncation behavior described in the issue. Done means using separate UTF-8 storage, respecting the wide output buffer limit, and ensuring the result is NUL-terminated; the issue also requests updating the macOS release tarball after a new release tag.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
When using the Google BigQuery ODBC Driver on macOS with iODBC (sizeof(SQLWCHAR) == 4) and Microsoft Excel / Microsoft Query, calling SQLDriverConnectW corrupts outConnectionString (szConnStrOut), causing Excel's Return Data action (inserting query results as a Table or PivotTable) to fail with:
[iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded
Root Cause Analysis
1. Latest Published Release (v1.3.1 / ODBCDriverforBigQuery_macos_latest.tar.gz)
In v1.3.1 (currently the latest binary published on GCS bq-driver-releases and GitHub Releases), SQLDriverConnectW in google/cloud/odbc/bq_driver/odbc_api.cc passed reinterpret_cast<SQLCHAR*>(outConnectionString) to SQLDriverConnectInternal() (which wrote 8-bit UTF-8 bytes into the caller's SQLWCHAR* buffer) and then executed:
outConnectionString = ToSqlWChar(utf16_out_conn_str->data());
Because outConnectionString is a pointer passed by value, reassigning the local parameter was a dead store (optimized out under -O3) and never copied the converted wide characters back into the caller's buffer. Consequently:
outConnectionStringstill contained raw 8-bit UTF-8 bytes (e.g.,"DSN=my-bq-dsn;").- On macOS,
iODBCreadsoutConnectionStringas 32-bitwchar_t(UTF-32LE) code units (0x3d4e5344, ...) and converts them into"??????". - When clicking Return Data in Microsoft Query on macOS,
Microsoft Query.apppassesOutConnectionStringtoMicrosoft Excel.appto open the worksheet connection, which immediately fails iniODBC.
2. Remaining Issues on main (google/cloud/odbc/bq_driver/odbc_api.cc:274-300)
Commit d080bdb282 (#1506) replaced the dead pointer assignment with:
WriteWideToWireBuffer(*utf16_out_conn_str, outConnectionString,
out_conn_str_len);
However, three issues remain in SQLDriverConnectW on main:
- Missing wire
NULterminator:WriteWideToWireBufferdefaults tobool null_terminate = false(odbc_type_utils.h:188), and unlikeSQLBrowseConnectW(odbc_api.cc:402),SQLDriverConnectWneither zerosoutConnectionStringbeforehand nor passes/*null_terminate=*/true. - Buffer overflow when
outConnectionStringBufferLentruncates the output: Per the ODBC specification,PopulateOutputConnectionStringsets*out_conn_str_lento the full untruncated string length even whenout_conn_str_buflenis smaller (SQL_SUCCESS_WITH_INFO/01004). Passingout_conn_str_lendirectly toWriteWideToWireBufferwithout clamping tooutConnectionStringBufferLen - 1writes past the end ofoutConnectionString, andUtf8ToUtf16((char*)out_conn_str)on line 287 ignoreselseonly becauseout_conn_str_len > 0. - Aliasing
outConnectionStringas a temporary UTF-8 buffer: CastingoutConnectionString(SQLWCHAR*) directly toSQLCHAR*aliases the caller's output buffer before wide conversion.
Proposed Fix (google/cloud/odbc/bq_driver/odbc_api.cc)
Use a separate temporary std::vector<SQLCHAR> buffer for SQLDriverConnectInternal, clamp the number of wide characters written to outConnectionStringBufferLen - 1, and pass /*null_terminate=*/true to WriteWideToWireBuffer:
std::vector<SQLCHAR> utf8_out_buf(
outConnectionString && outConnectionStringBufferLen > 0
? static_cast<size_t>(outConnectionStringBufferLen)
: 0,
0);
SQLCHAR* out_conn_str =
(!utf8_out_buf.empty()) ? utf8_out_buf.data() : nullptr;
SQLSMALLINT out_conn_str_len = 0;
rc = google::cloud::odbc_bq_driver::SQLDriverConnectInternal(
connectionHandle, windowHandle, sqlchar_in_connection_str,
inConnectionStringLen, out_conn_str, outConnectionStringBufferLen,
&out_conn_str_len, driverCompletion);
// Handle Unicode conversion of output parameters.
if (SQL_SUCCEEDED(rc) && outConnectionString) {
if (outConnectionStringBufferLen > 0) {
std::string val(ToCharStr(out_conn_str));
StatusRecordOr<std::wstring> utf16_out_conn_str = Utf8ToUtf16(val);
if (!utf16_out_conn_str) {
return utf16_out_conn_str.GetCalculatedReturnCode();
}
size_t const max_chars =
static_cast<size_t>(outConnectionStringBufferLen - 1);
size_t const to_copy =
std::min<size_t>(utf16_out_conn_str->size(), max_chars);
WriteWideToWireBuffer(*utf16_out_conn_str, outConnectionString, to_copy,
/*null_terminate=*/true);
} else if (outConnectionStringBufferLen == 0) {
// Buffer length is 0; do not write to outConnectionString.
}
}
if (outConnectionStringLen) *outConnectionStringLen = out_conn_str_len;
(Note: Once a new release tag is cut, please also update the macOS tarball at https://storage.googleapis.com/bq-driver-releases/odbc/ODBCDriverforBigQuery_macos_latest.tar.gz, which currently still serves v1.3.1.)
- Ngôn ngữ chính
- C++
- Star
- 5
- Fork
- 8
- Merge trung bình
- 2 ngày 14 giờ
- Pull request đã merge (30 ngày)
- 10
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của googleapis/cpp-bigquery-odbc
-
priority: p2 type: bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
googleapis/cpp-bigquery-odbc#1686 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Statement execution integration tests refactorCó thể làm lại được @sachinpro đã nhận 977 ngày trước và không có pull request nào đang mở. Đang mởpriority: p2 type: bug
googleapis/cpp-bigquery-odbc#271 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
priority: p2 type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
googleapis/cpp-bigquery-odbc#215 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Remove external dependencies from Unit TestsCó thể làm lại được @sachinpro đã nhận 1032 ngày trước và không có pull request nào đang mở. Đang mởpriority: p2 type: bug
googleapis/cpp-bigquery-odbc#195 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
priority: p2 type: cleanup
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
googleapis/cpp-bigquery-odbc#187 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của googleapis/cpp-bigquery-odbc
Issue tương tự
-
Reference check: findingsĐang mởaudit-reference-check
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
schrodinger/pymol-open-source#532 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
xlnt-community/xlnt#174 ·