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

call sheet.data_validation_cell crash #43

Open
cppcoffee opened this issue Feb 13, 2023 · 3 comments
Open

call sheet.data_validation_cell crash #43

cppcoffee opened this issue Feb 13, 2023 · 3 comments

Comments

@cppcoffee
Copy link

Reproduced rust source code.

main.rs

use anyhow::Result;
use xlsxwriter::{
    DataValidation, DataValidationCriteria, DataValidationErrorType, DataValidationType, Workbook,
};

fn main() -> Result<()> {
    let workbook = Workbook::new("./simple1.xlsx")?;

    let mut sheet1 = workbook.add_worksheet(None)?;
    sheet1.write_string(0, 0, "Red text", None)?;

    let mut validation = DataValidation::new(
        DataValidationType::List,
        DataValidationCriteria::None,
        DataValidationErrorType::Stop,
    );

    let list = build_value_list();

    validation.value_list = Some(list);

    sheet1.data_validation_cell(0, 1, &validation)?;

    workbook.close()?;

    Ok(())
}

fn build_value_list() -> Vec<String> {
    let res = vec![
        "8位 无符号".to_string(),
        "8位 有符号".to_string(),
        "16位 无符号(AB)".to_string(),
        "16位 无符号(BA)".to_string(),
        "16位 有符号(AB)".to_string(),
        "16位 有符号(BA)".to_string(),
        "32位 无符号(AB CD)".to_string(),
        "32位 无符号(CD AB)".to_string(),
        "32位 有符号(AB CD)".to_string(),
        "32位 有符号(CD AB)".to_string(),
        "32位 浮点数(AB CD)".to_string(),
        "32位 浮点数(CD AB)".to_string(),
        "64位 浮点数(AB CD)".to_string(),
        "64位 浮点数(CD AB)".to_string(),
        "位".to_string(),
    ];

    res
}

crash after running cargo run.

crash message:

demo(60168,0x1ed75fa80) malloc: Incorrect checksum for freed object 0x158604f88: probably modified after being freed.
Corrupt value: 0x28b095e6b982e7ae
demo(60168,0x1ed75fa80) malloc: *** set a breakpoint in malloc_error_break to debug
[1]    60168 abort      cargo run

maybe 2007 xlsx limit 255 chars?

@jmcnamara
Copy link

This looks like a libxlsxwriter issue. It checks that the number of characters is less than the Excel 255 limit (which it is) but uses a 255 8-bit char buffer instead of a 255 UTF-8 char buffer. Hence the overwrite and crash.

I'll fix it upstream. Tracking at jmcnamara/libxlsxwriter#394

@jmcnamara
Copy link

Fixed upstream on libxlsxwriter main.

@cppcoffee
Copy link
Author

Wow, that's great!

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

2 participants