mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 21:01:20 +00:00
Revert "Reland "fix hanging of write on Windows""
This reverts commitaf4a3112c4
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 ofeb075dcc21
> > 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>
This commit is contained in:
parent
5fc031ebc1
commit
f352f9e5e2
|
@ -161,8 +161,7 @@ int64_t File::Read(void* buffer, int64_t num_bytes) {
|
|||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
|
@ -56,13 +56,7 @@ bool File::WriteFully(const void* buffer, int64_t num_bytes) {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -146,8 +146,7 @@ int64_t File::Read(void* buffer, int64_t num_bytes) {
|
|||
|
||||
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);
|
||||
|
|
|
@ -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 @@ testWriteAsStringSync(dir) {
|
|||
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 @@ main() {
|
|||
var tempDir = Directory.systemTemp.createTempSync('dart_file_write_as');
|
||||
testWriteAsBytesSync(tempDir);
|
||||
testWriteAsStringSync(tempDir);
|
||||
testWriteWithLargeList(tempDir);
|
||||
testWriteAsBytes(tempDir).then((_) {
|
||||
return testWriteAsString(tempDir);
|
||||
}).then((_) {
|
||||
|
|
Loading…
Reference in a new issue