@@ -3111,8 +3111,10 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {
3111
3111
@compileError ("WASI does not support os.chdir" );
3112
3112
} else if (native_os == .windows ) {
3113
3113
var wtf16_dir_path : [windows .PATH_MAX_WIDE ]u16 = undefined ;
3114
- const len = try std .unicode .wtf8ToWtf16Le (wtf16_dir_path [0.. ], dir_path );
3115
- if (len > wtf16_dir_path .len ) return error .NameTooLong ;
3114
+ if (try std .unicode .checkWtf8ToWtf16LeOverflow (dir_path , & wtf16_dir_path )) {
3115
+ return error .NameTooLong ;
3116
+ }
3117
+ const len = try std .unicode .wtf8ToWtf16Le (& wtf16_dir_path , dir_path );
3116
3118
return chdirW (wtf16_dir_path [0.. len ]);
3117
3119
} else {
3118
3120
const dir_path_c = try toPosixPath (dir_path );
@@ -3126,9 +3128,12 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {
3126
3128
/// On other platforms, `dir_path` is an opaque sequence of bytes with no particular encoding.
3127
3129
pub fn chdirZ (dir_path : [* :0 ]const u8 ) ChangeCurDirError ! void {
3128
3130
if (native_os == .windows ) {
3131
+ const dir_path_span = mem .span (dir_path );
3129
3132
var wtf16_dir_path : [windows .PATH_MAX_WIDE ]u16 = undefined ;
3130
- const len = try std .unicode .wtf8ToWtf16Le (wtf16_dir_path [0.. ], mem .span (dir_path ));
3131
- if (len > wtf16_dir_path .len ) return error .NameTooLong ;
3133
+ if (try std .unicode .checkWtf8ToWtf16LeOverflow (dir_path_span , & wtf16_dir_path )) {
3134
+ return error .NameTooLong ;
3135
+ }
3136
+ const len = try std .unicode .wtf8ToWtf16Le (& wtf16_dir_path , dir_path_span );
3132
3137
return chdirW (wtf16_dir_path [0.. len ]);
3133
3138
} else if (native_os == .wasi and ! builtin .link_libc ) {
3134
3139
return chdir (mem .span (dir_path ));
0 commit comments