Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: sdk/lib/io/websocket_impl.dart

Issue 16363005: Ensure that only byte values are sent by sockets and web sockets (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed a few bugs Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | tests/standalone/io/raw_socket_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; 7 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
8 8
9 class _WebSocketMessageType { 9 class _WebSocketMessageType {
10 static const int NONE = 0; 10 static const int NONE = 0;
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 // Write the length in network byte order into the header. 524 // Write the length in network byte order into the header.
525 for (int i = 0; i < lengthBytes; i++) { 525 for (int i = 0; i < lengthBytes; i++) {
526 header[index++] = dataLength >> (((lengthBytes - 1) - i) * 8) & 0xFF; 526 header[index++] = dataLength >> (((lengthBytes - 1) - i) * 8) & 0xFF;
527 } 527 }
528 if (mask) { 528 if (mask) {
529 header[1] |= 1 << 7; 529 header[1] |= 1 << 7;
530 var maskBytes = _IOCrypto.getRandomBytes(4); 530 var maskBytes = _IOCrypto.getRandomBytes(4);
531 header.setRange(index, index + 4, maskBytes); 531 header.setRange(index, index + 4, maskBytes);
532 index += 4; 532 index += 4;
533 if (data != null) { 533 if (data != null) {
534 var list = new Uint8List(data.length); 534 var list;
535 for (int i = 0; i < data.length; i++) { 535 // If this is a text message just do the masking inside the
536 list[i] = data[i] ^ maskBytes[i % 4]; 536 // encoded data.
537 if (opcode == _WebSocketOpcode.TEXT) {
538 list = data;
539 } else {
540 list = new Uint8List(data.length);
541 }
542 if (data is Uint8List) {
543 for (int i = 0; i < data.length; i++) {
544 list[i] = data[i] ^ maskBytes[i % 4];
545 }
546 } else {
547 for (int i = 0; i < data.length; i++) {
548 if (data[i] < 0 || 255 < data[i]) {
549 throw new ArgumentError(
550 "List element is not a byte value "
551 "(value ${data[i]} at index $i)");
552 }
553 list[i] = data[i] ^ maskBytes[i % 4];
554 }
537 } 555 }
538 data = list; 556 data = list;
539 } 557 }
540 } 558 }
541 assert(index == headerSize); 559 assert(index == headerSize);
542 if (data == null) { 560 if (data == null) {
543 return [header]; 561 return [header];
544 } else { 562 } else {
545 return [header, data]; 563 return [header, data];
546 } 564 }
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 (code < WebSocketStatus.NORMAL_CLOSURE || 814 (code < WebSocketStatus.NORMAL_CLOSURE ||
797 code == WebSocketStatus.RESERVED_1004 || 815 code == WebSocketStatus.RESERVED_1004 ||
798 code == WebSocketStatus.NO_STATUS_RECEIVED || 816 code == WebSocketStatus.NO_STATUS_RECEIVED ||
799 code == WebSocketStatus.ABNORMAL_CLOSURE || 817 code == WebSocketStatus.ABNORMAL_CLOSURE ||
800 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && 818 (code > WebSocketStatus.INTERNAL_SERVER_ERROR &&
801 code < WebSocketStatus.RESERVED_1015) || 819 code < WebSocketStatus.RESERVED_1015) ||
802 (code >= WebSocketStatus.RESERVED_1015 && 820 (code >= WebSocketStatus.RESERVED_1015 &&
803 code < 3000)); 821 code < 3000));
804 } 822 }
805 } 823 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | tests/standalone/io/raw_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698