Skip to content

Commit f352f9e

Browse files
aamcommit-bot@chromium.org
authored andcommitted
Revert "Reland "fix hanging of write on Windows""
This reverts commit af4a311 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 eb075dc > > 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: #40339 > > Change-Id: I36fade62dfa3025f418405cb3e45c286dd6b7db1 > > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134440 > > Reviewed-by: Zach Anderson <[email protected]> > > Commit-Queue: Zichang Guo <[email protected]> > > Bug: #40339 > Change-Id: I5a07c58709c62b996a55a76272636602dc80e20d > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134783 > Commit-Queue: Zichang Guo <[email protected]> > Reviewed-by: Siva Annamalai <[email protected]> [email protected],[email protected],[email protected] Change-Id: I5f53e42c56859a46e9fe40e1a1e7fba541e5378e No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: #40339 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135260 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Alexander Aprelev <[email protected]>
1 parent 5fc031e commit f352f9e

File tree

4 files changed

+3
-32
lines changed

4 files changed

+3
-32
lines changed

runtime/bin/file_macos.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ int64_t File::Read(void* buffer, int64_t num_bytes) {
161161
}
162162

163163
int64_t File::Write(const void* buffer, int64_t num_bytes) {
164-
// Invalid argument error will pop if num_bytes exceeds the limit.
165-
ASSERT(handle_->fd() >= 0 && num_bytes <= kMaxInt32);
164+
ASSERT(handle_->fd() >= 0);
166165
return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes));
167166
}
168167

runtime/bin/file_support.cc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,7 @@ bool File::WriteFully(const void* buffer, int64_t num_bytes) {
5656
int64_t remaining = num_bytes;
5757
const char* current_buffer = reinterpret_cast<const char*>(buffer);
5858
while (remaining > 0) {
59-
// On Windows, narrowing conversion from int64_t to DWORD will cause
60-
// unexpected error.
61-
// On MacOS, a single write() with more than kMaxInt32 will have
62-
// "invalid argument" error.
63-
// Therefore, limit the size for single write.
64-
int64_t byte_to_write = num_bytes > kMaxInt32 ? kMaxInt32 : num_bytes;
65-
int64_t bytes_written = Write(current_buffer, byte_to_write);
59+
int64_t bytes_written = Write(current_buffer, remaining);
6660
if (bytes_written < 0) {
6761
return false;
6862
}

runtime/bin/file_win.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ int64_t File::Read(void* buffer, int64_t num_bytes) {
146146

147147
int64_t File::Write(const void* buffer, int64_t num_bytes) {
148148
int fd = handle_->fd();
149-
// Avoid narrowing conversion
150-
ASSERT(fd >= 0 && num_bytes <= MAXDWORD && num_bytes >= 0);
149+
ASSERT(fd >= 0);
151150
HANDLE handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
152151
DWORD written = 0;
153152
BOOL result = WriteFile(handle, buffer, num_bytes, &written, NULL);

tests/standalone_2/io/file_write_as_test.dart

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'dart:async';
66
import 'dart:io';
7-
import 'dart:typed_data';
87

98
import "package:async_helper/async_helper.dart";
109
import "package:expect/expect.dart";
@@ -28,25 +27,6 @@ testWriteAsStringSync(dir) {
2827
Expect.equals('$data$data', f.readAsStringSync());
2928
}
3029

31-
testWriteWithLargeList(dir) {
32-
// 0x100000000 exceeds the maximum of unsigned long.
33-
// This should no longer hang.
34-
// Issue: https://github.com/dart-lang/sdk/issues/40339
35-
var bytes;
36-
try {
37-
bytes = Uint8List(0x100000000);
38-
} catch (e) {
39-
// Create a big Uint8List may lead to OOM. This is acceptable.
40-
Expect.isTrue(e.toString().contains('Out of Memory'));
41-
return;
42-
}
43-
if (Platform.isWindows) {
44-
File('NUL').writeAsBytesSync(bytes);
45-
} else {
46-
File('/dev/null').writeAsBytesSync(bytes);
47-
}
48-
}
49-
5030
Future testWriteAsBytes(dir) {
5131
var completer = new Completer();
5232
var f = new File('${dir.path}/bytes.txt');
@@ -93,7 +73,6 @@ main() {
9373
var tempDir = Directory.systemTemp.createTempSync('dart_file_write_as');
9474
testWriteAsBytesSync(tempDir);
9575
testWriteAsStringSync(tempDir);
96-
testWriteWithLargeList(tempDir);
9776
testWriteAsBytes(tempDir).then((_) {
9877
return testWriteAsString(tempDir);
9978
}).then((_) {

0 commit comments

Comments
 (0)