mirror of
https://github.com/flutter/packages.git
synced 2025-06-29 22:33:11 +08:00
Merge pull request #27 from zanderso/handle-non-utf8
Catch FormatException in packet decoding.
This commit is contained in:
@ -1,3 +1,6 @@
|
|||||||
|
## 0.2.1
|
||||||
|
* Fixes the handling of packets containing non-utf8 strings.
|
||||||
|
|
||||||
## 0.2.0
|
## 0.2.0
|
||||||
* Allow configuration of the port and address the mdns query is performed on.
|
* Allow configuration of the port and address the mdns query is performed on.
|
||||||
|
|
||||||
|
@ -366,6 +366,9 @@ List<ResourceRecord> decodeMDnsResponse(List<int> packet) {
|
|||||||
} on MDnsDecodeException {
|
} on MDnsDecodeException {
|
||||||
// If decoding fails return null.
|
// If decoding fails return null.
|
||||||
return null;
|
return null;
|
||||||
|
} on FormatException {
|
||||||
|
// If decoding fails on a non-utf8 packet, return null.
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ name: multicast_dns
|
|||||||
description: Dart package for mDNS queries (e.g. Bonjour, Avahi).
|
description: Dart package for mDNS queries (e.g. Bonjour, Avahi).
|
||||||
author: Flutter Team <flutter-dev@googlegroups.com>
|
author: Flutter Team <flutter-dev@googlegroups.com>
|
||||||
homepage: https://github.com/flutter/packages/tree/master/packages/multicast_dns
|
homepage: https://github.com/flutter/packages/tree/master/packages/multicast_dns
|
||||||
version: 0.2.0
|
version: 0.2.1
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
meta: ^1.1.6
|
meta: ^1.1.6
|
||||||
|
@ -13,6 +13,7 @@ const int _kSrvHeaderSize = 6;
|
|||||||
void main() {
|
void main() {
|
||||||
testValidPackages();
|
testValidPackages();
|
||||||
testBadPackages();
|
testBadPackages();
|
||||||
|
testNonUtf8Packages();
|
||||||
// testHexDumpList();
|
// testHexDumpList();
|
||||||
testPTRRData();
|
testPTRRData();
|
||||||
testSRVRData();
|
testSRVRData();
|
||||||
@ -175,6 +176,12 @@ void testBadPackages() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testNonUtf8Packages() {
|
||||||
|
test('Returns null for non-utf8 text resource', () {
|
||||||
|
expect(decodeMDnsResponse(nonUtf8Package), isNull);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void testPTRRData() {
|
void testPTRRData() {
|
||||||
test('Can read FQDN from PTR data', () {
|
test('Can read FQDN from PTR data', () {
|
||||||
expect('sgjesse-macbookpro2 [78:31:c1:b8:55:38]._workstation._tcp.local',
|
expect('sgjesse-macbookpro2 [78:31:c1:b8:55:38]._workstation._tcp.local',
|
||||||
@ -1178,3 +1185,255 @@ const List<int> packetWithoutQuestionWithAnArCount = <int>[
|
|||||||
50,
|
50,
|
||||||
51,
|
51,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Package with a text resource that is not valid utf8.
|
||||||
|
const List<int> nonUtf8Package = <int>[
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x84,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x08,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x1f,
|
||||||
|
0x72,
|
||||||
|
0x61,
|
||||||
|
0x73,
|
||||||
|
0x70,
|
||||||
|
0x62,
|
||||||
|
0x65,
|
||||||
|
0x72,
|
||||||
|
0x72,
|
||||||
|
0x79,
|
||||||
|
0x70,
|
||||||
|
0x69,
|
||||||
|
0x20,
|
||||||
|
0x5b,
|
||||||
|
0x62,
|
||||||
|
0x38,
|
||||||
|
0x3a,
|
||||||
|
0x32,
|
||||||
|
0x37,
|
||||||
|
0x3a,
|
||||||
|
0x65,
|
||||||
|
0x62,
|
||||||
|
0xd2,
|
||||||
|
0x30,
|
||||||
|
0x33,
|
||||||
|
0x3a,
|
||||||
|
0x39,
|
||||||
|
0x32,
|
||||||
|
0x3a,
|
||||||
|
0x34,
|
||||||
|
0x62,
|
||||||
|
0x5d,
|
||||||
|
0x0c,
|
||||||
|
0x5f,
|
||||||
|
0x77,
|
||||||
|
0x6f,
|
||||||
|
0x72,
|
||||||
|
0x6b,
|
||||||
|
0x73,
|
||||||
|
0x74,
|
||||||
|
0x61,
|
||||||
|
0x74,
|
||||||
|
0x69,
|
||||||
|
0x6f,
|
||||||
|
0x6e,
|
||||||
|
0x04,
|
||||||
|
0x5f,
|
||||||
|
0x74,
|
||||||
|
0x63,
|
||||||
|
0x70,
|
||||||
|
0x05,
|
||||||
|
0x6c,
|
||||||
|
0x6f,
|
||||||
|
0x63,
|
||||||
|
0x61,
|
||||||
|
0x6c,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x10,
|
||||||
|
0x80,
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x11,
|
||||||
|
0x94,
|
||||||
|
0x00,
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
0x0b,
|
||||||
|
0x5f,
|
||||||
|
0x75,
|
||||||
|
0x64,
|
||||||
|
0x69,
|
||||||
|
0x73,
|
||||||
|
0x6b,
|
||||||
|
0x73,
|
||||||
|
0x2d,
|
||||||
|
0x73,
|
||||||
|
0x73,
|
||||||
|
0x68,
|
||||||
|
0xc0,
|
||||||
|
0x39,
|
||||||
|
0x00,
|
||||||
|
0x0c,
|
||||||
|
0x00,
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x11,
|
||||||
|
0x94,
|
||||||
|
0x00,
|
||||||
|
0x0e,
|
||||||
|
0x0b,
|
||||||
|
0x72,
|
||||||
|
0x61,
|
||||||
|
0x73,
|
||||||
|
0x70,
|
||||||
|
0x62,
|
||||||
|
0x65,
|
||||||
|
0x72,
|
||||||
|
0x72,
|
||||||
|
0x79,
|
||||||
|
0x70,
|
||||||
|
0x69,
|
||||||
|
0xc0,
|
||||||
|
0x50,
|
||||||
|
0xc0,
|
||||||
|
0x68,
|
||||||
|
0x00,
|
||||||
|
0x21,
|
||||||
|
0x80,
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x78,
|
||||||
|
0x00,
|
||||||
|
0x14,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x16,
|
||||||
|
0x0b,
|
||||||
|
0x72,
|
||||||
|
0x61,
|
||||||
|
0x73,
|
||||||
|
0x70,
|
||||||
|
0x62,
|
||||||
|
0x65,
|
||||||
|
0x72,
|
||||||
|
0x72,
|
||||||
|
0x79,
|
||||||
|
0x70,
|
||||||
|
0x69,
|
||||||
|
0xc0,
|
||||||
|
0x3e,
|
||||||
|
0xc0,
|
||||||
|
0x68,
|
||||||
|
0x00,
|
||||||
|
0x10,
|
||||||
|
0x80,
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x11,
|
||||||
|
0x94,
|
||||||
|
0x00,
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
0x09,
|
||||||
|
0x5f,
|
||||||
|
0x73,
|
||||||
|
0x65,
|
||||||
|
0x72,
|
||||||
|
0x76,
|
||||||
|
0x69,
|
||||||
|
0x63,
|
||||||
|
0x65,
|
||||||
|
0x73,
|
||||||
|
0x07,
|
||||||
|
0x5f,
|
||||||
|
0x64,
|
||||||
|
0x6e,
|
||||||
|
0x73,
|
||||||
|
0x2d,
|
||||||
|
0x73,
|
||||||
|
0x64,
|
||||||
|
0x04,
|
||||||
|
0x5f,
|
||||||
|
0x75,
|
||||||
|
0x64,
|
||||||
|
0x70,
|
||||||
|
0xc0,
|
||||||
|
0x3e,
|
||||||
|
0x00,
|
||||||
|
0x0c,
|
||||||
|
0x00,
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x11,
|
||||||
|
0x94,
|
||||||
|
0x00,
|
||||||
|
0x02,
|
||||||
|
0xc0,
|
||||||
|
0x50,
|
||||||
|
0xc0,
|
||||||
|
0x2c,
|
||||||
|
0x00,
|
||||||
|
0x0c,
|
||||||
|
0x00,
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x11,
|
||||||
|
0x94,
|
||||||
|
0x00,
|
||||||
|
0x02,
|
||||||
|
0xc0,
|
||||||
|
0x0c,
|
||||||
|
0xc0,
|
||||||
|
0x0c,
|
||||||
|
0x00,
|
||||||
|
0x21,
|
||||||
|
0x80,
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x78,
|
||||||
|
0x00,
|
||||||
|
0x08,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x09,
|
||||||
|
0xc0,
|
||||||
|
0x88,
|
||||||
|
0xc0,
|
||||||
|
0xa3,
|
||||||
|
0x00,
|
||||||
|
0x0c,
|
||||||
|
0x00,
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x11,
|
||||||
|
0x94,
|
||||||
|
0x00,
|
||||||
|
0x02,
|
||||||
|
0xc0,
|
||||||
|
0x2c
|
||||||
|
];
|
||||||
|
Reference in New Issue
Block a user