[GH-ISSUE #442] Bug: workbook_validate_sheet_name buffer-overflow #348

Closed
opened 2026-05-05 12:11:10 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @ym-xie on GitHub (May 8, 2024).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/442

Originally assigned to: @jmcnamara on GitHub.

hello, maybe there exist a bug in workbook_validate_sheet_name.
When sheetname is an empty string (""), the workbook_validate_sheet_name function does not check if the string length is 0, leading to a buffer overflow.The following is the relevant code, the crash occurs at workbook.c:workbook_validate_sheet_name.

#include "xlsxwriter.h"

int main() {

    lxw_workbook  *workbook  = workbook_new("demo.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    const char* name = "";
    lxw_error le = workbook_validate_sheet_name(workbook, name);
    if (le == LXW_NO_ERROR) {
      lxw_worksheet *worksheet = workbook_add_worksheet(workbook, name);
    }

    return 0;
}
Originally created by @ym-xie on GitHub (May 8, 2024). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/442 Originally assigned to: @jmcnamara on GitHub. hello, maybe there exist a bug in workbook_validate_sheet_name. When `sheetname` is an empty string (`""`), the `workbook_validate_sheet_name` function does not check if the string length is 0, leading to a buffer overflow.The following is the relevant code, the crash occurs at workbook.c:workbook_validate_sheet_name. ```c #include "xlsxwriter.h" int main() { lxw_workbook *workbook = workbook_new("demo.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); const char* name = ""; lxw_error le = workbook_validate_sheet_name(workbook, name); if (le == LXW_NO_ERROR) { lxw_worksheet *worksheet = workbook_add_worksheet(workbook, name); } return 0; } ```
gitea-mirror 2026-05-05 12:11:10 -06:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@jmcnamara commented on GitHub (May 8, 2024):

Thanks for the report. That is omission/bug. I'll add a fix.

<!-- gh-comment-id:2101015458 --> @jmcnamara commented on GitHub (May 8, 2024): Thanks for the report. That is omission/bug. I'll add a fix.
Author
Owner

@jmcnamara commented on GitHub (May 8, 2024):

I've pushed a fix for this to main. There is now a new error code called LXW_ERROR_SHEETNAME_IS_BLANK for this condition.

<!-- gh-comment-id:2101260654 --> @jmcnamara commented on GitHub (May 8, 2024): I've pushed a fix for this to main. There is now a new error code called `LXW_ERROR_SHEETNAME_IS_BLANK` for this condition.
Author
Owner

@ym-xie commented on GitHub (May 9, 2024):

Should verify in advance that name is NULL?

<!-- gh-comment-id:2101817519 --> @ym-xie commented on GitHub (May 9, 2024): Should verify in advance that `name` is NULL?
Author
Owner

@jmcnamara commented on GitHub (May 9, 2024):

Should verify in advance that name is NULL?

My initial thought was that the end user should check for NULL and that workbook_validate_sheet_name() should validate the name and not the string. However, most libxlsxwriter functions check for NULL so I've added a LXW_ERROR_NULL_PARAMETER_IGNORED error as well.

I've force pushed that change to main.

<!-- gh-comment-id:2102104082 --> @jmcnamara commented on GitHub (May 9, 2024): > Should verify in advance that `name` is NULL? My initial thought was that the end user should check for NULL and that `workbook_validate_sheet_name()` should validate the name and not the string. However, most libxlsxwriter functions check for `NULL` so I've added a `LXW_ERROR_NULL_PARAMETER_IGNORED` error as well. I've force pushed that change to main.
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#348
No description provided.