Revert "Reland "fix hanging of write on Windows""
This reverts commit af4a3112c41239780ffc09d5a284c146d142071b as it broke asan linux bot.
Reason for revert: <INSERT REASONING HERE>
Original change's description:
> Reland "fix hanging of write on Windows"
>
> This is a reland of eb075dcc21fc45abd4218caea7f7bbcde212105b
>
> Original change's description:
> > fix hanging of write on Windows
> >
> > When using File::Write(), Var size in int64_t is casted to DWORD(unsigned long). When Var size is out of DWORD range, casted value will be zero. Before calling into File::Write() on Windows, validate the size.
> >
> > Bug: https://github.com/dart-lang/sdk/issues/40339
> > Change-Id: I36fade62dfa3025f418405cb3e45c286dd6b7db1
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134440
> > Reviewed-by: Zach Anderson <zra@google.com>
> > Commit-Queue: Zichang Guo <zichangguo@google.com>
>
> Bug: https://github.com/dart-lang/sdk/issues/40339
> Change-Id: I5a07c58709c62b996a55a76272636602dc80e20d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134783
> Commit-Queue: Zichang Guo <zichangguo@google.com>
> Reviewed-by: Siva Annamalai <asiva@google.com>
TBR=zra@google.com,asiva@google.com,zichangguo@google.com
Change-Id: I5f53e42c56859a46e9fe40e1a1e7fba541e5378e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/40339
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135260
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
diff --git a/runtime/bin/file_macos.cc b/runtime/bin/file_macos.cc
index d763add..334252e 100644
--- a/runtime/bin/file_macos.cc
+++ b/runtime/bin/file_macos.cc
@@ -161,8 +161,7 @@
}
int64_t File::Write(const void* buffer, int64_t num_bytes) {
- // Invalid argument error will pop if num_bytes exceeds the limit.
- ASSERT(handle_->fd() >= 0 && num_bytes <= kMaxInt32);
+ ASSERT(handle_->fd() >= 0);
return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes));
}
diff --git a/runtime/bin/file_support.cc b/runtime/bin/file_support.cc
index c67e3e3..dd07839 100644
--- a/runtime/bin/file_support.cc
+++ b/runtime/bin/file_support.cc
@@ -56,13 +56,7 @@
int64_t remaining = num_bytes;
const char* current_buffer = reinterpret_cast<const char*>(buffer);
while (remaining > 0) {
- // On Windows, narrowing conversion from int64_t to DWORD will cause
- // unexpected error.
- // On MacOS, a single write() with more than kMaxInt32 will have
- // "invalid argument" error.
- // Therefore, limit the size for single write.
- int64_t byte_to_write = num_bytes > kMaxInt32 ? kMaxInt32 : num_bytes;
- int64_t bytes_written = Write(current_buffer, byte_to_write);
+ int64_t bytes_written = Write(current_buffer, remaining);
if (bytes_written < 0) {
return false;
}
diff --git a/runtime/bin/file_win.cc b/runtime/bin/file_win.cc
index bc4c6b1..cfcae15 100644
--- a/runtime/bin/file_win.cc
+++ b/runtime/bin/file_win.cc
@@ -146,8 +146,7 @@
int64_t File::Write(const void* buffer, int64_t num_bytes) {
int fd = handle_->fd();
- // Avoid narrowing conversion
- ASSERT(fd >= 0 && num_bytes <= MAXDWORD && num_bytes >= 0);
+ ASSERT(fd >= 0);
HANDLE handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
DWORD written = 0;
BOOL result = WriteFile(handle, buffer, num_bytes, &written, NULL);
diff --git a/tests/standalone_2/io/file_write_as_test.dart b/tests/standalone_2/io/file_write_as_test.dart
index db851c9..ce13ebd 100644
--- a/tests/standalone_2/io/file_write_as_test.dart
+++ b/tests/standalone_2/io/file_write_as_test.dart
@@ -4,7 +4,6 @@
import 'dart:async';
import 'dart:io';
-import 'dart:typed_data';
import "package:async_helper/async_helper.dart";
import "package:expect/expect.dart";
@@ -28,25 +27,6 @@
Expect.equals('$data$data', f.readAsStringSync());
}
-testWriteWithLargeList(dir) {
- // 0x100000000 exceeds the maximum of unsigned long.
- // This should no longer hang.
- // Issue: https://github.com/dart-lang/sdk/issues/40339
- var bytes;
- try {
- bytes = Uint8List(0x100000000);
- } catch (e) {
- // Create a big Uint8List may lead to OOM. This is acceptable.
- Expect.isTrue(e.toString().contains('Out of Memory'));
- return;
- }
- if (Platform.isWindows) {
- File('NUL').writeAsBytesSync(bytes);
- } else {
- File('/dev/null').writeAsBytesSync(bytes);
- }
-}
-
Future testWriteAsBytes(dir) {
var completer = new Completer();
var f = new File('${dir.path}/bytes.txt');
@@ -93,7 +73,6 @@
var tempDir = Directory.systemTemp.createTempSync('dart_file_write_as');
testWriteAsBytesSync(tempDir);
testWriteAsStringSync(tempDir);
- testWriteWithLargeList(tempDir);
testWriteAsBytes(tempDir).then((_) {
return testWriteAsString(tempDir);
}).then((_) {