https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43196

--- Comment #5 from David Nind <[email protected]> ---
Created attachment 203355
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=203355&action=edit
Bug 43196: Reject malformed MARC records in PUT /biblios

MARC::Record parsers silently return empty records on invalid input:
- new_from_mij_structure(undef) returns a blank record (MiJ)
- new_from_usmarc(garbage) returns a blank record with warnings
- new_from_xml(valid-but-empty) returns a blank record

The PUT /biblios endpoint passed these blank records to ModBiblio,
which overwrote existing bibliographic data with an empty record
(only system-generated 005 and 999 fields survive).

Wrap each parser call in try/catch (for MARCXML which dies on
malformed XML) and validate the resulting record has at least one
field before proceeding. Return 400 if parsing fails or produces
an empty record.

Note: MARC::Record::MiJ upstream has been patched to croak on
undef/invalid input (perl4lib/marc-perl#28), but Koha needs this
defensive check regardless for USMARC and empty-but-valid cases.

Test plan:
1. Apply the regression tests from the previous commit
2. Run:
   $ prove t/db_dependent/api/v1/biblios.t
=> FAIL: put() malformed body tests fail
3. Apply this patch
4. Repeat step 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: Tomás Cohen Arazi <[email protected]>
Signed-off-by: David Nind <[email protected]>

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to