Skip to content

Commit 424c254

Browse files
a-sivaCommit Queue
authored and
Commit Queue
committed
[VM/Runtime] Ensure errno is saved to ensure it is not clobbered by a subsequent operation.
This should fix the issue raised in #50129 TEST=ci (requires a massive file which is over 2 GB to be created) Change-Id: Ib6163e015ff8506bd6de6b65dc433398857379d6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376820 Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Siva Annamalai <[email protected]>
1 parent 838e4a2 commit 424c254

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

runtime/bin/file.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ void FUNCTION_NAME(File_ReadInto)(Dart_NativeArguments args) {
252252
}
253253

254254
int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length);
255+
OSError os_error; // capture error if any
255256
if (is_byte_data) {
256257
ThrowIfError(Dart_TypedDataReleaseData(buffer_obj));
257258
}
@@ -261,7 +262,7 @@ void FUNCTION_NAME(File_ReadInto)(Dart_NativeArguments args) {
261262
}
262263
Dart_SetIntegerReturnValue(args, bytes_read);
263264
} else {
264-
Dart_SetReturnValue(args, DartUtils::NewDartOSError());
265+
Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error));
265266
}
266267
}
267268

@@ -1145,8 +1146,9 @@ CObject* File::ReadRequest(const CObjectArray& request) {
11451146
uint8_t* data = io_buffer->value.as_external_typed_data.data;
11461147
const int64_t bytes_read = file->Read(data, length);
11471148
if (bytes_read < 0) {
1149+
CObject* error = CObject::NewOSError();
11481150
CObject::FreeIOBufferData(io_buffer);
1149-
return CObject::NewOSError();
1151+
return error;
11501152
}
11511153

11521154
// Possibly shrink the used malloc() storage if the actual number of bytes is
@@ -1180,8 +1182,9 @@ CObject* File::ReadIntoRequest(const CObjectArray& request) {
11801182
uint8_t* data = io_buffer->value.as_external_typed_data.data;
11811183
const int64_t bytes_read = file->Read(data, length);
11821184
if (bytes_read < 0) {
1185+
CObject* error = CObject::NewOSError();
11831186
CObject::FreeIOBufferData(io_buffer);
1184-
return CObject::NewOSError();
1187+
return error;
11851188
}
11861189

11871190
// Possibly shrink the used malloc() storage if the actual number of bytes is

0 commit comments

Comments
 (0)