@@ -300,14 +300,18 @@ struct PSBTInput
300300 template <typename Stream>
301301 inline void Unserialize (Stream& s) {
302302 // Read loop
303+ bool found_sep = false ;
303304 while (!s.empty ()) {
304305 // Read
305306 std::vector<unsigned char > key;
306307 s >> key;
307308
308309 // the key is empty if that was actually a separator byte
309310 // This is a special case for key lengths 0 as those are not allowed (except for separator)
310- if (key.empty ()) return ;
311+ if (key.empty ()) {
312+ found_sep = true ;
313+ break ;
314+ }
311315
312316 // First byte of key is the type
313317 unsigned char type = key[0 ];
@@ -422,6 +426,10 @@ struct PSBTInput
422426 break ;
423427 }
424428 }
429+
430+ if (!found_sep) {
431+ throw std::ios_base::failure (" Separator is missing at the end of an input map" );
432+ }
425433 }
426434
427435 template <typename Stream>
@@ -475,14 +483,18 @@ struct PSBTOutput
475483 template <typename Stream>
476484 inline void Unserialize (Stream& s) {
477485 // Read loop
486+ bool found_sep = false ;
478487 while (!s.empty ()) {
479488 // Read
480489 std::vector<unsigned char > key;
481490 s >> key;
482491
483492 // the key is empty if that was actually a separator byte
484493 // This is a special case for key lengths 0 as those are not allowed (except for separator)
485- if (key.empty ()) return ;
494+ if (key.empty ()) {
495+ found_sep = true ;
496+ break ;
497+ }
486498
487499 // First byte of key is the type
488500 unsigned char type = key[0 ];
@@ -527,6 +539,10 @@ struct PSBTOutput
527539 }
528540 }
529541 }
542+
543+ if (!found_sep) {
544+ throw std::ios_base::failure (" Separator is missing at the end of an output map" );
545+ }
530546 }
531547
532548 template <typename Stream>
@@ -602,14 +618,18 @@ struct PartiallySignedTransaction
602618 }
603619
604620 // Read global data
621+ bool found_sep = false ;
605622 while (!s.empty ()) {
606623 // Read
607624 std::vector<unsigned char > key;
608625 s >> key;
609626
610627 // the key is empty if that was actually a separator byte
611628 // This is a special case for key lengths 0 as those are not allowed (except for separator)
612- if (key.empty ()) break ;
629+ if (key.empty ()) {
630+ found_sep = true ;
631+ break ;
632+ }
613633
614634 // First byte of key is the type
615635 unsigned char type = key[0 ];
@@ -649,6 +669,10 @@ struct PartiallySignedTransaction
649669 }
650670 }
651671
672+ if (!found_sep) {
673+ throw std::ios_base::failure (" Separator is missing at the end of the global map" );
674+ }
675+
652676 // Make sure that we got an unsigned tx
653677 if (!tx) {
654678 throw std::ios_base::failure (" No unsigned transcation was provided" );
0 commit comments