[io/win] Ensure File_WriteFrom and File_Read report non-zero error code.
BUG=https://github.com/dart-lang/sdk/issues/48721
TEST=file_error2_test,file_fuzz_test on win ia32
Change-Id: I260c3fa46bc737db741b3b9ae9172c939648aa6c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239861
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc
index d7eda14..92a3b65 100644
--- a/runtime/bin/file.cc
+++ b/runtime/bin/file.cc
@@ -203,7 +203,8 @@
uint8_t* buffer = NULL;
Dart_Handle external_array = IOBuffer::Allocate(length, &buffer);
if (Dart_IsNull(external_array)) {
- Dart_SetReturnValue(args, DartUtils::NewDartOSError());
+ OSError os_error(-1, "Failed to allocate buffer", OSError::kUnknown);
+ Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error));
return;
}
int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length);
@@ -289,11 +290,13 @@
// Write all the data out into the file.
char* byte_buffer = reinterpret_cast<char*>(buffer);
bool success = file->WriteFully(byte_buffer + start, length);
+ OSError os_error; // capture error if any
// Release the direct pointer acquired above.
ThrowIfError(Dart_TypedDataReleaseData(buffer_obj));
+
if (!success) {
- Dart_SetReturnValue(args, DartUtils::NewDartOSError());
+ Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error));
} else {
Dart_SetReturnValue(args, Dart_Null());
}