[Bug 43021] New: A single malformed Z39.50/SRU result can break search and staged record preview
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43021 Bug ID: 43021 Summary: A single malformed Z39.50/SRU result can break search and staged record preview Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Z39.50 / SRU / OpenSearch Servers 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 related, unguarded MARC decode calls in the Z39.50/SRU search and staged record ("breeding") preview flow: 1. C4::Breeding::_handle_one_result (C4/Breeding.pm) calls MARC::Record->new_from_xml on each SRU search result with no eval. The caller loop that iterates search results across all configured servers already has per-result error handling for other kinds of failures (connection diagnostics collected in @errconn), but this call bypasses it entirely - one malformed record from any searched server aborts the whole results page for the cataloguer running the search. 2. MARCfindbreeding in cataloguing/addbiblio.pl calls MARC::Record->new_from_usmarc on a staged ("breeding") record with no eval, when a cataloguer opens that staged record to preview/import it. Both should catch a decode failure for the one affected record and report it to the user (e.g. skip that result with a visible message, or show a clear error instead of a blank/broken page) rather than propagating an uncaught exception. Found while auditing other places in the codebase that ingest externally-sourced MARC data, prompted by bug 35104. Test plan: 1. Configure a Z39.50/SRU target and search it for records, where at least one result server returns a record whose MARC cannot be decoded (or simulate by mocking C4::Breeding::_handle_one_result's input). 2. Before a fix: the whole results page fails/errors out. 3. Separately, stage a file containing an undecodable record via Stage MARC records for import, then open it via the cataloguing "breeding" preview. 4. Before a fix: the preview page errors out. 5. After a fix: both cases show a clear per-record error and let the user continue working with the rest of the results/batch. 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 the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43021 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=43021 Phil Ringnalda <phil@chetcolibrary.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |phil@chetcolibrary.org -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43021 Manos PETRIDIS <egpetridis@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |egpetridis@yahoo.com --- Comment #1 from Manos PETRIDIS <egpetridis@yahoo.com> --- I wonder if the changes proposed in https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41794 could be of help here. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43021 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on|35104 |43025 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 https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43025 [Bug 43025] Show metadata repair warnings in the cataloguing edit form -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43021 --- Comment #2 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 211487 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211487&action=edit Bug 43021: Skip undecodable Z39.50/SRU results and staged records A single malformed record from a Z39.50/SRU server could break the whole cataloguing search, and an undecodable staged record could break the breeding preview. C4::Breeding::_handle_one_result decoded SRU results with no eval, so one bad record aborted the results page. The non-SRU branch and the XSLT re-decode in _do_xslt_proc had the same problem, and an empty record from a failed MARC parse was silently stored as a result. Now an undecodable result is logged with Koha::Logger, skipped, and reported as a per-result message ("could not be decoded and was skipped"), while the other results still render. MARCfindbreeding in cataloguing/addbiblio.pl had the same unguarded new_from_usmarc call. A staged record that cannot be decoded is now logged and the addbiblio page shows a clear error instead of dying. To test: 1. Configure a Z39.50 or SRU server in Administration > Z39.50/SRU servers that returns at least one record with broken MARC, or simulate it by feeding a non-MARC blob through C4::Breeding. 2. Go to Cataloguing > Z39.50/SRU search and search that server. 3. Before this patch: the results page errors out. 4. After this patch: the page still shows the other results, and an alert lists the skipped record as "could not be decoded and was skipped". A line is written to the Koha log. 5. Stage a file containing an undecodable record under Tools > Stage MARC records for import, then open that staged record from the breeding preview (cataloguing/addbiblio.pl?breedingid=...). 6. Before this patch: the page errors out. 7. After this patch: the page shows the "could not be decoded" alert and no crash. 8. Run prove t/db_dependent/Breeding.t. All tests 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=43021 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=43021 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Sponsorship status|--- |Sponsored Comma delimited| |OpenFifth list of Sponsors| | Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43021 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #211487|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=43021 --- Comment #3 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Created attachment 211590 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211590&action=edit Bug 43021: Skip undecodable Z39.50/SRU results and staged records A single malformed record from a Z39.50/SRU server could break the whole cataloguing search, and an undecodable staged record could break the breeding preview. C4::Breeding::_handle_one_result decoded SRU results with no eval, so one bad record aborted the results page. The non-SRU branch and the XSLT re-decode in _do_xslt_proc had the same problem, and an empty record from a failed MARC parse was silently stored as a result. Now an undecodable result is logged with Koha::Logger, skipped, and reported as a per-result message ("could not be decoded and was skipped"), while the other results still render. MARCfindbreeding in cataloguing/addbiblio.pl had the same unguarded new_from_usmarc call. A staged record that cannot be decoded is now logged and the addbiblio page shows a clear error instead of dying. To test: 1. Configure a Z39.50 or SRU server in Administration > Z39.50/SRU servers that returns at least one record with broken MARC, or simulate it by feeding a non-MARC blob through C4::Breeding. 2. Go to Cataloguing > Z39.50/SRU search and search that server. 3. Before this patch: the results page errors out. 4. After this patch: the page still shows the other results, and an alert lists the skipped record as "could not be decoded and was skipped". A line is written to the Koha log. 5. Stage a file containing an undecodable record under Tools > Stage MARC records for import, then open that staged record from the breeding preview (cataloguing/addbiblio.pl?breedingid=...). 6. Before this patch: the page errors out. 7. After this patch: the page shows the "could not be decoded" alert and no crash. 8. Run prove t/db_dependent/Breeding.t. All tests 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=43021 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |adolfo.rodriguez@xercode.es --- Comment #4 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Tested both parts: Z39.50/SRU search: I set up a fake SRU server that answers any search with two records, one valid MARCXML and one broken ("<record><leader", sent with recordPacking=string), and added it as an SRU server (sru_options: sru=get,sru_version=1.1). - Before the patch, the Z39.50/SRU search page died with a 500 and the parser error in the log. - After the patch, the valid record is listed, the alert says "Record could not be decoded and was skipped (ref. MARC_DECODE) for <server> result 2", and the log has "Skipping a result from z39.50/SRU server <server> that could not be decoded: ...". Staged record: a copy of an existing import_records row with its marc replaced by a non-MARC blob, opened at cataloguing/addbiblio.pl?breedingid=<id>. - Before the patch, the page loaded an empty form with no notice, and nothing was logged (new_from_usmarc does not die on this blob, it returns a record with no fields). - After the patch, the page shows "The staged record could not be decoded, it cannot be previewed or imported", and an error naming the staged record is logged. t/db_dependent/Breeding.t passes. The QA script flags pod_coverage on C4/Breeding.pm, but that is pre-existing: the subs listed are private subs already on main without POD, and the new _decode_failure has its POD. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43021 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit |nick@bywatersolutions.com |y.org | -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org