Closed Bug 1793415 Opened 2 years ago Closed 2 years ago

Invalid vCards throw error messages and break the addressBook API

Categories

(Thunderbird :: Address Book, defect)

Thunderbird 102
defect

Tracking

(thunderbird_esr102 fixed)

RESOLVED FIXED
107 Branch
Tracking Status
thunderbird_esr102 --- fixed

People

(Reporter: myaddons, Assigned: darktrojan)

References

Details

Attachments

(3 files, 1 obsolete file)

Attached file contact.vcf

A user of my add-on Mail Merge reported a problem after the upgrade from Thunderbird 91 / Mail Merge 8 to Thunderbird 102 / Mail Merge 9. After a few hours of analyzing the problem we figured out, that a bug in Thunderbird was ultimately causing the problem.

My add-on uses the addressBooks API and contacts API to get a list of all address books and all contacts.

However, a simple call to messenger.contacts.get(addressbook.id) failed for one specific address book, i.e. the Personal Address Book, while the same call succeeded for other address books, e.g. Collected Addresses. The culprit was a particular contact in the affected address book - see contact.vcf.

This (ghost) contact was probably created by Thunderbird during the upgrade from 91 to 102. The user says he did not create the contact manually. And I don't think the user could have created this contact within Thunderbird - even if he tried - because Thunderbird simply doesn't allow to create such a contact.

Importing the contact manually via "Address Book -> Import -> vCard" does work. Afterwards the contact is also shown in the contact list in the address book window. However, selecting the contact throws this error message in the error console:

Uncaught Error: Could not extract integer from "NaN-"
    strictParseInt resource:///modules/calendar/Ical.jsm:154
    part resource:///modules/calendar/Ical.jsm:6322
    fromDateAndOrTimeString resource:///modules/calendar/Ical.jsm:6337
    formatDate chrome://messenger/content/addressbook/aboutAddressBook.js:2895
    displayContact chrome://messenger/content/addressbook/aboutAddressBook.js:2943
    displayCards chrome://messenger/content/addressbook/aboutAddressBook.js:2659
    _onSelect chrome://messenger/content/addressbook/aboutAddressBook.js:2095
    handleEvent chrome://messenger/content/addressbook/aboutAddressBook.js:1508
    _selectSingle chrome://messenger/content/tree-listbox.js:1592
    connectedCallback chrome://messenger/content/tree-listbox.js:1060
Ical.jsm:154:13

Searching for the contact in the address book window throws this error:

Could not extract integer from "NaN-" Ical.jsm:154
    strictParseInt resource:///modules/calendar/Ical.jsm:154
    part resource:///modules/calendar/Ical.jsm:6322
    fromDateAndOrTimeString resource:///modules/calendar/Ical.jsm:6337
    toAbCard resource:///modules/VCardUtils.jsm:404
    InterpretGeneratorResume self-hosted:1422
    next self-hosted:1370
    toPropertyMap resource:///modules/VCardUtils.jsm:918
    results resource:///modules/AddrBookDirectory.jsm:379
    filter self-hosted:198
    search resource:///modules/AddrBookDirectory.jsm:369
    ABView chrome://messenger/content/addressbook/abView-new.js:28
    _onCommand chrome://messenger/content/addressbook/aboutAddressBook.js:2008
    handleEvent chrome://messenger/content/addressbook/aboutAddressBook.js:1502
    _fireCommand chrome://messenger/content/addressbook/aboutAddressBook.js:1183
    _fireCommand self-hosted:1115

Autocompletion in the To field in the compose window throws this error:

Could not extract integer from "NaN-" Ical.jsm:154
    strictParseInt resource:///modules/calendar/Ical.jsm:154
    part resource:///modules/calendar/Ical.jsm:6322
    fromDateAndOrTimeString resource:///modules/calendar/Ical.jsm:6337
    toAbCard resource:///modules/VCardUtils.jsm:404
    InterpretGeneratorResume self-hosted:1422
    next self-hosted:1370
    toPropertyMap resource:///modules/VCardUtils.jsm:918
    results resource:///modules/AddrBookDirectory.jsm:379
    filter self-hosted:198
    search resource:///modules/AddrBookDirectory.jsm:369
    _searchCards resource:///modules/AbAutoCompleteSearch.jsm:222
    _searchCards resource:///modules/AbAutoCompleteSearch.jsm:221
    startSearch resource:///modules/AbAutoCompleteSearch.jsm:478

I don't know, how the (ghost) contact has been created in the first place. I suspect this to be some kind of problem during the upgrade from Thunderbird 91 to 102. But as I can't provide any kind of useful information, e.g. steps to reproduce, I didn't file a dedicated bug, yet.

Anyway, an invalid contact like this can be easily imported either manually or especially via CardDAV. So I recommend to harden Thunderbird in a way, that invalid vCards or invalid vCard properties are handled gracefully.

There was a similar bug fixed just a few weeks ago in Thunderbird 102.3.0: https://bugzilla.mozilla.org/show_bug.cgi?id=1789793

As I said in the very beginning, I discovered the problem via calling messenger.contacts.list(addressbook.id) - see test.xpi:

Could not extract integer from "NaN-" Ical.jsm:154
    strictParseInt resource:///modules/calendar/Ical.jsm:154
    part resource:///modules/calendar/Ical.jsm:6322
    fromDateAndOrTimeString resource:///modules/calendar/Ical.jsm:6337
    toAbCard resource:///modules/VCardUtils.jsm:404
    InterpretGeneratorResume self-hosted:1422
    next self-hosted:1370
    toPropertyMap resource:///modules/VCardUtils.jsm:918
    convert chrome://messenger/content/parent/ext-addressBook.js:391
    convert chrome://messenger/content/parent/ext-addressBook.js:360
    map self-hosted:180
    convert chrome://messenger/content/parent/ext-addressBook.js:360
    list chrome://messenger/content/parent/ext-addressBook.js:764
    list self-hosted:1115
    result resource://gre/modules/ExtensionParent.jsm:1035
    withCallContextData resource://gre/modules/ExtensionParent.jsm:524
    result resource://gre/modules/ExtensionParent.jsm:1034
    withPendingBrowser resource://gre/modules/ExtensionParent.jsm:534
    result resource://gre/modules/ExtensionParent.jsm:1033
    callAndLog resource://gre/modules/ExtensionParent.jsm:986
    recvAPICall resource://gre/modules/ExtensionParent.jsm:1032
    AsyncFunctionNext self-hosted:632
Error: An unexpected error occurred undefined
    <anonymous> moz-extension://99cd659f-f96c-4062-979a-ed0b883254b7/background.js:9
    AsyncFunctionThrow self-hosted:636
    (Async: async)
    <anonymous> moz-extension://99cd659f-f96c-4062-979a-ed0b883254b7/background.js:4

Unfortunately the error is not handled gracefully in this case as well. The call does not succeed, i.e. no contacts are returned, but the execution is simply stopped. Even using try...catch does not work from within the add-on.

Attached file test.xpi (obsolete) —

Thanks, I'll deal with this.

Assignee: nobody → geoff
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true

The parsing may fail but that shouldn't break things.

Changes to test_vCard.js are mostly reinstating a test I should not have removed (in https://hg.mozilla.org/comm-central/diff/7b22f4a4287431034851651aa94fa6c88717e235/mailnews/addrbook/test/unit/test_vCard.js) with some additional cases in the birthday section.

I just tested the patch on top of comm-esr102 and it works fine now!

Attached file test.xpi

While testing the patch I discovered I had initially uploaded the wrong file by mistake.

This is now the correct test case for an add-on, which uses messenger.addressBooks.list() and messenger.contacts.list(). Running the add-on in vanilla comm-esr102 (Stable 102.3.1) results in the previously mentioned error and does not print the contacts of the address books in the error console.

With the patch applied on top of comm-esr102 it also works fine now and prints the contacts of the address books in the error console - just as it should be.

Attachment #9296968 - Attachment is obsolete: true

Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/e5e6ef8f77b6
Catch and report errors parsing dates from vCards. r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 107 Branch

Comment on attachment 9297058 [details]
Bug 1793415 - Catch and report errors parsing dates from vCards. r=#thunderbird-reviewers

[Approval Request Comment]
Regression caused by (bug #): never worked
User impact if declined: broken data = broken address book UI
Testing completed (on c-c, etc.): in 107b1
Risk to taking this patch (and alternatives if risky): effectively just a try/catch

Attachment #9297058 - Flags: approval-comm-esr102?

Comment on attachment 9297058 [details]
Bug 1793415 - Catch and report errors parsing dates from vCards. r=#thunderbird-reviewers

[Triage Comment]
Approved for esr102

Attachment #9297058 - Flags: approval-comm-esr102? → approval-comm-esr102+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: