[GH-ISSUE #394] Crash when data validation list exceeds 255 char limit with UTF-8 characters #315

Closed
opened 2026-05-05 12:08:31 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @jmcnamara on GitHub (Feb 22, 2023).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/394

There is an issue with when creating a data validation where the UTF-8 length exceeds 255 characters. Libxlsxwriter checks that the number of characters is less than the Excel 255 limit but uses a 255 8-bit char buffer instead of a 255 UTF-8 char buffer. This leads to a crash as demonstrated by the following code.

#include "xlsxwriter.h"

int main() {

    lxw_workbook  *workbook  = workbook_new("test_data_validation.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    char *list[] = {
        "8位 无符号",
        "8位 有符号",
        "16位 无符号(AB)",
        "16位 无符号(BA)",
        "16位 有符号(AB)",
        "16位 有符号(BA)",
        "32位 无符号(AB CD)",
        "32位 无符号(CD AB)",
        "32位 有符号(AB CD)",
        "32位 有符号(CD AB)",
        "32位 浮点数(AB CD)",
        "32位 浮点数(CD AB)",
        "64位 浮点数(AB CD)",
        "64位 浮点数(CD AB)",
        "位",
        NULL};

    lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
    data_validation->validate = LXW_VALIDATION_TYPE_LIST;
    data_validation->value_list = list;
    data_validation->input_title = "This is the input title";
    data_validation->input_message = "This is the input message";

    worksheet_data_validation_cell(worksheet, CELL("C2"), data_validation);

    free(data_validation);

    return workbook_close(workbook);
}

See also: https://github.com/informationsea/xlsxwriter-rs/issues/43

Originally created by @jmcnamara on GitHub (Feb 22, 2023). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/394 There is an issue with when creating a data validation where the UTF-8 length exceeds 255 characters. Libxlsxwriter checks that the number of characters is less than the Excel 255 limit but uses a 255 8-bit char buffer instead of a 255 UTF-8 char buffer. This leads to a crash as demonstrated by the following code. ```C #include "xlsxwriter.h" int main() { lxw_workbook *workbook = workbook_new("test_data_validation.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); char *list[] = { "8位 无符号", "8位 有符号", "16位 无符号(AB)", "16位 无符号(BA)", "16位 有符号(AB)", "16位 有符号(BA)", "32位 无符号(AB CD)", "32位 无符号(CD AB)", "32位 有符号(AB CD)", "32位 有符号(CD AB)", "32位 浮点数(AB CD)", "32位 浮点数(CD AB)", "64位 浮点数(AB CD)", "64位 浮点数(CD AB)", "位", NULL}; lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation)); data_validation->validate = LXW_VALIDATION_TYPE_LIST; data_validation->value_list = list; data_validation->input_title = "This is the input title"; data_validation->input_message = "This is the input message"; worksheet_data_validation_cell(worksheet, CELL("C2"), data_validation); free(data_validation); return workbook_close(workbook); } ``` See also: https://github.com/informationsea/xlsxwriter-rs/issues/43
Author
Owner

@jmcnamara commented on GitHub (Feb 22, 2023):

Fixed on main;

Screenshot 2023-02-22 at 13 09 14

<!-- gh-comment-id:1439995705 --> @jmcnamara commented on GitHub (Feb 22, 2023): Fixed on main; ![Screenshot 2023-02-22 at 13 09 14](https://user-images.githubusercontent.com/94267/220629628-eb7c33cb-c38b-406e-8077-ce6da8efadcb.png)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#315
No description provided.