Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
MAX_ENCODING_SIZE -> MAX_CP_LEN
  • Loading branch information
serhiy-storchaka committed Aug 1, 2025
commit eae0bc4e7309902ae7d170fdfffd647cf35f0f70
6 changes: 3 additions & 3 deletions Modules/_localemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ copy_grouping(const char* s)

#if defined(MS_WINDOWS)

// The number of elements in the szCodePage field
// 16 is the number of elements in the szCodePage field
// of the __crt_locale_strings structure.
#define MAX_ENCODING_SIZE 16
#define MAX_CP_LEN 15

static int
check_locale_name(const char *locale, const char *end)
{
size_t len = end ? (size_t)(end - locale) : strlen(locale);
const char *dot = memchr(locale, '.', len);
if (dot && locale + len - dot > MAX_ENCODING_SIZE) {
if (dot && locale + len - dot - 1 > MAX_CP_LEN) {
return -1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you get the "16" from ?
Please include some comments to explain where you got it from and why this check is necessary. Thanks.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW: It's better to make this limit configurable via a constant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comes from https://github.com/huangqinjin/ucrt/blob/d6e817a4cc90f6f1fe54f8a0aa4af4fff0bb647d/inc/corecrt_internal.h#L401, though I don't think that constant is available for us at compile time (the internal headers for the CRT are, well, internal).

A constant at least gives it a name though, and using MAX_CP_LEN may help someone find an updated definition in the future.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now.

}
return 0;
Expand Down
Loading