[Bug 43024] New: A couple of lower-traffic paths don't guard against undecodable MARC either
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43024 Bug ID: 43024 Summary: A couple of lower-traffic paths don't guard against undecodable MARC either Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: minor Priority: P5 - low Component: Cataloging Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: testopia@bugs.koha-community.org CC: m.de.rooy@rijksmuseum.nl Depends on: 35104 Target Milestone: --- Two lower-traffic, isolated spots with the same unguarded-MARC-decode pattern as bug 35104 and its other follow-ups, found during the same audit but rated lower priority since they're narrower/rarer code paths: 1. C4::Items::_parse_unlinked_item_subfields_from_xml (C4/Items.pm) calls MARC::Record->new_from_xml on an item's more_subfields_xml with no eval. This would only be hit if that column's content is itself malformed, which would usually already have failed at storage time - but there's no guard here if it happens anyway (e.g. data imported directly into the DB, or written before item metadata was validated on save). 2. C4::Record::marc2endnote (C4/Record.pm) calls MARC::Record->new_from_usmarc with no eval, when exporting a record to EndNote format. A record with undecodable stored MARC would fail the export with no clear message, though this failure is isolated to the one export action and doesn't cascade. Found while auditing other places in the codebase that ingest/re-decode MARC data, prompted by bug 35104. Filed for tracking; lower priority than the other bugs from the same audit given how narrow and rarely-hit these two paths are. Test plan: 1. Get an item with undecodable more_subfields_xml (e.g. via direct DB manipulation), then trigger whatever code path calls _parse_unlinked_item_subfields_from_xml for it. 2. Get a biblio with undecodable stored MARCXML, then export it via whatever UI/API path calls marc2endnote. 3. Before a fix: both die with an unhandled exception. 4. After a fix: both fail gracefully with a clear message. Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=35104 [Bug 35104] We should warn when attempting to save MARC records that contain characters invalid in XML -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43024 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |martin.renvoize@openfifth.c |ity.org |o.uk -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43024 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 211488 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211488&action=edit Bug 43024: Guard undecodable MARC in item subfields and EndNote export C4::Items::_parse_unlinked_item_subfields_from_xml decoded the item's more_subfields_xml with no eval, so one malformed value would abort Item2Marc. It now logs a warning via Koha::Logger, naming the itemnumber, and returns undef, so the item is rendered without its unlinked subfields. C4::Record::marc2endnote decoded its input with no eval. It now accepts a MARC::Record object as well as an ISO2709 string (the catalogue and OPAC export scripts pass objects, which the function previously mis-decoded to empty output), and returns ( $error, $endnote ) like marc2marc and changeEncoding. On a decode failure it logs and returns a clear error message. catalogue/export.pl and opac/opac-export.pl are updated to use the new return values and report the error to the user. To test: 1. Set more_subfields_xml on an item to '<record><leader>truncated' (for example with UPDATE items SET more_subfields_xml=... WHERE itemnumber=N). 2. View the biblio in the staff interface, or edit or view the item: the page loads, the item is shown, and a warning appears in the Koha log. 3. Before this patch, Item2Marc dies with an XML parse error. 4. Go to Catalogue > Export records for a biblio and choose EndNote. With valid data the .enw file downloads and contains the title. Previously, the file was empty. 5. Run: prove t/db_dependent/Items.t t/db_dependent/Record.t Both pass. Sponsored-by: OpenFifth Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43024 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43024 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |44074 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44074 [Bug 44074] Koha::Item columns_to_str and additional_attributes do not guard undecodable more_subfields_xml -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43024 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Comma delimited| |OpenFifth list of Sponsors| | Status|Needs Signoff |Signed Off Sponsorship status|--- |Sponsored -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43024 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #211488|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43024 --- Comment #2 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Created attachment 211616 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211616&action=edit Bug 43024: Guard undecodable MARC in item subfields and EndNote export C4::Items::_parse_unlinked_item_subfields_from_xml decoded the item's more_subfields_xml with no eval, so one malformed value would abort Item2Marc. It now logs a warning via Koha::Logger, naming the itemnumber, and returns undef, so the item is rendered without its unlinked subfields. C4::Record::marc2endnote decoded its input with no eval. It now accepts a MARC::Record object as well as an ISO2709 string (the catalogue and OPAC export scripts pass objects, which the function previously mis-decoded to empty output), and returns ( $error, $endnote ) like marc2marc and changeEncoding. On a decode failure it logs and returns a clear error message. catalogue/export.pl and opac/opac-export.pl are updated to use the new return values and report the error to the user. To test: 1. Set more_subfields_xml on an item to '<record><leader>truncated' (for example with UPDATE items SET more_subfields_xml=... WHERE itemnumber=N). 2. View the biblio in the staff interface, or edit or view the item: the page loads, the item is shown, and a warning appears in the Koha log. 3. Before this patch, Item2Marc dies with an XML parse error. 4. Go to Catalogue > Export records for a biblio and choose EndNote. With valid data the .enw file downloads and contains the title. Previously, the file was empty. 5. Run: prove t/db_dependent/Items.t t/db_dependent/Record.t Both pass. Sponsored-by: OpenFifth Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Adolfo Rodríguez <adolfo.rodriguez@xercode.es> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43024 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |adolfo.rodriguez@xercode.es --- Comment #3 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Tested on current main: - C4::Items::GetMarcItem on an item whose more_subfields_xml is '<record><leader>truncated': before the patch it died with the XML parse error; after it, it returns the item field without the unlinked subfields and logs "Ignoring undecodable more_subfields_xml for item (itemnumber=...)". - EndNote export from the staff interface (catalogue/export.pl) and the OPAC (opac-export.pl, with endnote added to OpacExportOptions): before the patch the .enw file only had the "DB" line, with no title or author; after it, it has T1 and A1 as expected. Note for QA: step 2 of the test plan (viewing or exporting the record with the broken item) still fails with this patch alone, because those pages go through Koha::Item->additional_attributes, which bug 44074 guards. The QA script is happy, and t/db_dependent/Items.t and t/db_dependent/Record.t pass. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43024 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit |lucas@bywatersolutions.com |y.org | -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org