From 73a605764d8ae338f2014aea396bf3c88bf719fe Mon Sep 17 00:00:00 2001 From: Leon Han Date: Tue, 26 Nov 2019 11:27:36 +0000 Subject: [PATCH] Bug 1598207 [wpt PR 20332] - [webnfc] Fix code trying to access a null pointer, a=testonly Automatic update from web-platform-tests [webnfc] Fix code trying to access a null pointer This CL fixes a bug introduced by crrev.com/c/1824395 that attempts to access null pointer, also adds a wpt to cover it. BUG=520391,1026541 Change-Id: I62d5b28c3c6d39cbb27c2f21ca4d5ca91e54d892 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1925494 Commit-Queue: Leon Han Reviewed-by: Rijubrata Bhaumik Reviewed-by: Reilly Grant Cr-Commit-Position: refs/heads/master@{#717487} -- wpt-commits: 5ee699a2d83f07e88b0dbfd7938711bab1fe6cfc wpt-pr: 20332 --- .../web-nfc/NDEFRecord_constructor.https.html | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/testing/web-platform/tests/web-nfc/NDEFRecord_constructor.https.html b/testing/web-platform/tests/web-nfc/NDEFRecord_constructor.https.html index 79ce8a076eda..d0322316e8b8 100644 --- a/testing/web-platform/tests/web-nfc/NDEFRecord_constructor.https.html +++ b/testing/web-platform/tests/web-nfc/NDEFRecord_constructor.https.html @@ -46,6 +46,8 @@ const decoder = new TextDecoder(); assert_equals(decoder.decode(record.data), test_text_data, 'data has the same content with the original dictionary'); + assert_throws('NotSupportedError', () => record.toRecords(), + 'Only smart-poster records and external type records could have embedded records.'); }, 'NDEFRecord constructor with text record type and string data'); test(() => { @@ -59,6 +61,8 @@ const decoder = new TextDecoder(); assert_equals(decoder.decode(record.data), test_text_data, 'data has the same content with the original dictionary'); + assert_throws('NotSupportedError', () => record.toRecords(), + 'Only smart-poster records and external type records could have embedded records.'); }, 'NDEFRecord constructor with text record type and arrayBuffer data'); test(() => { @@ -72,6 +76,8 @@ const decoder = new TextDecoder(); assert_equals(decoder.decode(record.data), test_text_data, 'data has the same content with the original dictionary'); + assert_throws('NotSupportedError', () => record.toRecords(), + 'Only smart-poster records and external type records could have embedded records.'); }, 'NDEFRecord constructor with text record type and arrayBufferView data'); test(() => { @@ -113,6 +119,8 @@ const decoder = new TextDecoder(); assert_equals(decoder.decode(record.data), test_url_data, 'data has the same content with the original dictionary'); + assert_throws('NotSupportedError', () => record.toRecords(), + 'Only smart-poster records and external type records could have embedded records.'); }, 'NDEFRecord constructor with url record type'); test(() => { @@ -122,6 +130,8 @@ const decoder = new TextDecoder(); assert_equals(decoder.decode(record.data), test_url_data, 'data has the same content with the original dictionary'); + assert_throws('NotSupportedError', () => record.toRecords(), + 'Only smart-poster records and external type records could have embedded records.'); }, 'NDEFRecord constructor with absolute-url record type'); test(() => { @@ -138,6 +148,8 @@ assert_equals(record.mediaType, 'application/octet-stream', 'mediaType'); assert_array_equals(new Uint8Array(record.data.buffer), [1, 2, 3, 4], 'data has the same content with the original buffer'); + assert_throws('NotSupportedError', () => record.toRecords(), + 'Only smart-poster records and external type records could have embedded records.'); } // Feed ArrayBufferView. { @@ -146,6 +158,8 @@ assert_equals(record.recordType, 'mime', 'recordType'); assert_array_equals(new Uint8Array(record.data.buffer), [2, 3, 4], 'data has the same content with the original buffer view'); + assert_throws('NotSupportedError', () => record.toRecords(), + 'Only smart-poster records and external type records could have embedded records.'); } }, 'NDEFRecord constructor with mime record type and stream data'); @@ -156,6 +170,8 @@ assert_object_equals(JSON.parse(new TextDecoder().decode(record.data)), test_json_data, 'data has the same content with the original json'); + assert_throws('NotSupportedError', () => record.toRecords(), + 'Only smart-poster records and external type records could have embedded records.'); }, 'NDEFRecord constructor with mime record type and json data'); test(() => { @@ -171,6 +187,8 @@ assert_equals(record.recordType, 'unknown', 'recordType'); assert_array_equals(new Uint8Array(record.data.buffer), [1, 2, 3, 4], 'data has the same content with the original buffer'); + assert_throws('NotSupportedError', () => record.toRecords(), + 'Only smart-poster records and external type records could have embedded records.'); } // Feed ArrayBufferView. { @@ -179,6 +197,8 @@ assert_equals(record.recordType, 'unknown', 'recordType'); assert_array_equals(new Uint8Array(record.data.buffer), [2, 3, 4], 'data has the same content with the original buffer view'); + assert_throws('NotSupportedError', () => record.toRecords(), + 'Only smart-poster records and external type records could have embedded records.'); } }, 'NDEFRecord constructor with unknown record type'); @@ -192,6 +212,8 @@ assert_equals(record.mediaType, null, 'mediaType'); assert_array_equals(new Uint8Array(record.data.buffer), original_data, 'data has the same content with the original buffer'); + assert_equals(record.toRecords(), null, + 'toRecords() returns null if the payload is not an NDEF message.'); }, 'NDEFRecord constructor with external record type'); test(() => {