[Bug 43023] New: A single record with corrupt metadata can break rendering of search results
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43023 Bug ID: 43023 Summary: A single record with corrupt metadata can break rendering of search results Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Searching Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: testopia@bugs.koha-community.org Depends on: 35104 Target Milestone: --- Two unguarded MARC decode calls in search result rendering: 1. C4::Search::searchResults (C4/Search.pm), the "scan" search branch, calls MARC::Record->new_from_usmarc directly on each raw Zebra scan result with no eval. 2. C4::Search::new_record_from_zebra's Elasticsearch fast path (C4/Search.pm) returns MARC::Record->new_from_xml($raw_data, 'UTF-8') directly, without the eval wrapper that the Zebra dom/grs1 branches further down in the same sub already have. If a corrupted record ends up in the index (e.g. left over from a legacy import, or synced from a source that had this problem), rendering the result list can die for that page of results instead of degrading gracefully for the one bad record. Found while auditing other places in the codebase that ingest externally-sourced MARC data, prompted by bug 35104. Test plan: 1. Get a record with undecodable stored metadata into the search index (e.g. via direct DB manipulation of biblio_metadata before reindexing, or by reindexing a legacy corrupt record). 2. Run a scan search, and separately a normal search, that includes that record among the results, on both a Zebra and an Elasticsearch installation. 3. Before a fix: the results page/list can die instead of just omitting or flagging that one result. 4. After a fix: the rest of the results render normally. 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=43023 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=43023 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 211485 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211485&action=edit Bug 43023: Skip undecodable records instead of aborting search results A single record whose stored MARC cannot be decoded can make the whole page of search results die. Several paths decode each hit without any guard: - C4::Search::searchResults, the scan branch, calls MARC::Record->new_from_usmarc on every raw scan result with no eval. - C4::Search::new_record_from_zebra, the Elasticsearch fast path, returns MARC::Record->new_from_xml without the eval that the Zebra DOM and GRS-1 branches already have. - Koha::SearchEngine::Elasticsearch::Search::search_compat decodes each hit with decode_record_from_result, with no eval, so one bad hit aborts the whole result set. - opac/opac-search.pl decodes the supplemental authority results without a guard. Each of these now logs the record that failed and skips it, so the rest of the page still renders. search_compat leaves an undefined hole at the failed position so that offsets still line up with the page being rendered. searchResults and Koha::Biblio->get_marc_components skip those holes. This follows the same per-record isolation as the existing Zebra branches, which already skip undecodable records. To test: 1. Run prove t/db_dependent/Search/UndecodableRecords.t inside KTD. Before this patch it dies on the malformed scan record. After it all 12 tests pass. 2. Optional, on a Zebra install: run a scan search and a normal search that includes a record with corrupt stored metadata. Before the patch the results page can die. After it, the bad record is missing from the list and the rest render, with an "ERROR DECODING" line in the log. 3. Optional, on an Elasticsearch install: index a record whose marc_data is not valid MARCXML or ISO2709, then run a search that returns it. The other results should still render. 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=43023 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=43023 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=43023 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #211485|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=43023 --- Comment #2 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Created attachment 211589 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211589&action=edit Bug 43023: Skip undecodable records instead of aborting search results A single record whose stored MARC cannot be decoded can make the whole page of search results die. Several paths decode each hit without any guard: - C4::Search::searchResults, the scan branch, calls MARC::Record->new_from_usmarc on every raw scan result with no eval. - C4::Search::new_record_from_zebra, the Elasticsearch fast path, returns MARC::Record->new_from_xml without the eval that the Zebra DOM and GRS-1 branches already have. - Koha::SearchEngine::Elasticsearch::Search::search_compat decodes each hit with decode_record_from_result, with no eval, so one bad hit aborts the whole result set. - opac/opac-search.pl decodes the supplemental authority results without a guard. Each of these now logs the record that failed and skips it, so the rest of the page still renders. search_compat leaves an undefined hole at the failed position so that offsets still line up with the page being rendered. searchResults and Koha::Biblio->get_marc_components skip those holes. This follows the same per-record isolation as the existing Zebra branches, which already skip undecodable records. To test: 1. Run prove t/db_dependent/Search/UndecodableRecords.t inside KTD. Before this patch it dies on the malformed scan record. After it all 12 tests pass. 2. Optional, on a Zebra install: run a scan search and a normal search that includes a record with corrupt stored metadata. Before the patch the results page can die. After it, the bad record is missing from the list and the rest render, with an "ERROR DECODING" line in the log. 3. Optional, on an Elasticsearch install: index a record whose marc_data is not valid MARCXML or ISO2709, then run a search that returns it. The other results should still render. 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=43023 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 Elasticsearch: three records matching the same search, with the marc_data of one of them replaced in the index by broken MARCXML. - Before the patch, both the staff and the OPAC search returned "No results found" with the parser error ("EndTag: '</' not found"), hiding the two good records. - After the patch, both show the two good records, and the log has "ERROR DECODING ELASTICSEARCH RECORD <biblionumber>". One observation, not a blocker: the result count still includes the skipped record ("Your search returned 3 results" with 2 listed). I understand that comes from leaving the hole so the offsets line up, but it might be worth a follow-up. The QA script is happy, and t/db_dependent/Search/UndecodableRecords.t, t/db_dependent/Search.t and t/db_dependent/Koha/SearchEngine/Elasticsearch/Search.t pass -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43023 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit |andrew@bywatersolutions.com |y.org | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43023 Andrew Fuerste-Henry <andrew@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Passed QA -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43023 Andrew Fuerste-Henry <andrew@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #211589|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=43023 --- Comment #4 from Andrew Fuerste-Henry <andrew@bywatersolutions.com> --- Created attachment 212446 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212446&action=edit Bug 43023: Skip undecodable records instead of aborting search results A single record whose stored MARC cannot be decoded can make the whole page of search results die. Several paths decode each hit without any guard: - C4::Search::searchResults, the scan branch, calls MARC::Record->new_from_usmarc on every raw scan result with no eval. - C4::Search::new_record_from_zebra, the Elasticsearch fast path, returns MARC::Record->new_from_xml without the eval that the Zebra DOM and GRS-1 branches already have. - Koha::SearchEngine::Elasticsearch::Search::search_compat decodes each hit with decode_record_from_result, with no eval, so one bad hit aborts the whole result set. - opac/opac-search.pl decodes the supplemental authority results without a guard. Each of these now logs the record that failed and skips it, so the rest of the page still renders. search_compat leaves an undefined hole at the failed position so that offsets still line up with the page being rendered. searchResults and Koha::Biblio->get_marc_components skip those holes. This follows the same per-record isolation as the existing Zebra branches, which already skip undecodable records. To test: 1. Run prove t/db_dependent/Search/UndecodableRecords.t inside KTD. Before this patch it dies on the malformed scan record. After it all 12 tests pass. 2. Optional, on a Zebra install: run a scan search and a normal search that includes a record with corrupt stored metadata. Before the patch the results page can die. After it, the bad record is missing from the list and the rest render, with an "ERROR DECODING" line in the log. 3. Optional, on an Elasticsearch install: index a record whose marc_data is not valid MARCXML or ISO2709, then run a search that returns it. The other results should still render. Sponsored-by: OpenFifth Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Adolfo Rodríguez <adolfo.rodriguez@xercode.es> Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org