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

Crash when data validation list exceeds 255 char limit with UTF-8 characters #394

Closed
jmcnamara opened this issue Feb 22, 2023 · 1 comment

Comments

@jmcnamara
Copy link
Owner

jmcnamara commented Feb 22, 2023

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: informationsea/xlsxwriter-rs#43

@jmcnamara
Copy link
Owner Author

Fixed on main;

Screenshot 2023-02-22 at 13 09 14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant