@@ -403,13 +403,15 @@ static PyObject* PyUpb_DescriptorPool_FindFileByName(PyObject* _self,
403403 const char * name = PyUpb_VerifyStrData (arg );
404404 if (!name ) return NULL ;
405405
406- const upb_FileDef * file = upb_DefPool_FindFileByName (self -> symtab , name );
406+ const upb_FileDef * file = upb_DefPool_FindFileByNameWithSize (
407+ self -> symtab , name , PyObject_Size (arg ));
407408 if (file == NULL && self -> db ) {
408409 if (!PyUpb_DescriptorPool_TryLoadFilename (self , arg )) return NULL ;
409- file = upb_DefPool_FindFileByName (self -> symtab , name );
410+ file = upb_DefPool_FindFileByNameWithSize (self -> symtab , name ,
411+ PyObject_Size (arg ));
410412 }
411413 if (file == NULL ) {
412- return PyErr_Format (PyExc_KeyError , "Couldn't find file %.200s " , name );
414+ return PyErr_Format (PyExc_KeyError , "Couldn't find file %S " , arg );
413415 }
414416
415417 return PyUpb_FileDescriptor_Get (file );
@@ -428,14 +430,15 @@ static PyObject* PyUpb_DescriptorPool_FindExtensionByName(PyObject* _self,
428430 const char * name = PyUpb_VerifyStrData (arg );
429431 if (!name ) return NULL ;
430432
431- const upb_FieldDef * field =
432- upb_DefPool_FindExtensionByName ( self -> symtab , name );
433+ const upb_FieldDef * field = upb_DefPool_FindExtensionByNameWithSize (
434+ self -> symtab , name , PyObject_Size ( arg ) );
433435 if (field == NULL && self -> db ) {
434436 if (!PyUpb_DescriptorPool_TryLoadSymbol (self , arg )) return NULL ;
435- field = upb_DefPool_FindExtensionByName (self -> symtab , name );
437+ field = upb_DefPool_FindExtensionByNameWithSize (self -> symtab , name ,
438+ PyObject_Size (arg ));
436439 }
437440 if (field == NULL ) {
438- return PyErr_Format (PyExc_KeyError , "Couldn't find extension %.200s " , name );
441+ return PyErr_Format (PyExc_KeyError , "Couldn't find extension %S " , arg );
439442 }
440443
441444 return PyUpb_FieldDescriptor_Get (field );
@@ -453,14 +456,16 @@ static PyObject* PyUpb_DescriptorPool_FindMessageTypeByName(PyObject* _self,
453456
454457 const char * name = PyUpb_VerifyStrData (arg );
455458 if (!name ) return NULL ;
459+ Py_ssize_t name_size = PyObject_Size (arg );
456460
457- const upb_MessageDef * m = upb_DefPool_FindMessageByName (self -> symtab , name );
461+ const upb_MessageDef * m =
462+ upb_DefPool_FindMessageByNameWithSize (self -> symtab , name , name_size );
458463 if (m == NULL && self -> db ) {
459464 if (!PyUpb_DescriptorPool_TryLoadSymbol (self , arg )) return NULL ;
460- m = upb_DefPool_FindMessageByName (self -> symtab , name );
465+ m = upb_DefPool_FindMessageByNameWithSize (self -> symtab , name , name_size );
461466 }
462467 if (m == NULL ) {
463- return PyErr_Format (PyExc_KeyError , "Couldn't find message %.200s " , name );
468+ return PyErr_Format (PyExc_KeyError , "Couldn't find message %S " , arg );
464469 }
465470
466471 return PyUpb_Descriptor_Get (m );
@@ -502,12 +507,13 @@ static PyObject* PyUpb_DescriptorPool_FindFieldByName(PyObject* _self,
502507 parent_size );
503508 }
504509 if (parent ) {
505- f = upb_MessageDef_FindFieldByName (parent , child );
510+ f = upb_MessageDef_FindFieldByNameWithSize (
511+ parent , child , PyObject_Size (arg ) - parent_size - 1 );
506512 }
507513 }
508514
509515 if (!f ) {
510- return PyErr_Format (PyExc_KeyError , "Couldn't find message %.200s " , name );
516+ return PyErr_Format (PyExc_KeyError , "Couldn't find field %S " , arg );
511517 }
512518
513519 return PyUpb_FieldDescriptor_Get (f );
@@ -526,13 +532,15 @@ static PyObject* PyUpb_DescriptorPool_FindEnumTypeByName(PyObject* _self,
526532 const char * name = PyUpb_VerifyStrData (arg );
527533 if (!name ) return NULL ;
528534
529- const upb_EnumDef * e = upb_DefPool_FindEnumByName (self -> symtab , name );
535+ const upb_EnumDef * e = upb_DefPool_FindEnumByNameWithSize (self -> symtab , name ,
536+ PyObject_Size (arg ));
530537 if (e == NULL && self -> db ) {
531538 if (!PyUpb_DescriptorPool_TryLoadSymbol (self , arg )) return NULL ;
532- e = upb_DefPool_FindEnumByName (self -> symtab , name );
539+ e = upb_DefPool_FindEnumByNameWithSize (self -> symtab , name ,
540+ PyObject_Size (arg ));
533541 }
534542 if (e == NULL ) {
535- return PyErr_Format (PyExc_KeyError , "Couldn't find enum %.200s " , name );
543+ return PyErr_Format (PyExc_KeyError , "Couldn't find enum %S " , arg );
536544 }
537545
538546 return PyUpb_EnumDescriptor_Get (e );
@@ -563,12 +571,16 @@ static PyObject* PyUpb_DescriptorPool_FindOneofByName(PyObject* _self,
563571 parent_size );
564572 }
565573 if (parent ) {
566- const upb_OneofDef * o = upb_MessageDef_FindOneofByName (parent , child );
574+ const upb_OneofDef * o = upb_MessageDef_FindOneofByNameWithSize (
575+ parent , child , PyObject_Size (arg ) - parent_size - 1 );
576+ if (!o ) {
577+ return PyErr_Format (PyExc_KeyError , "Couldn't find oneof %S" , arg );
578+ }
567579 return PyUpb_OneofDescriptor_Get (o );
568580 }
569581 }
570582
571- return PyErr_Format (PyExc_KeyError , "Couldn't find oneof %.200s " , name );
583+ return PyErr_Format (PyExc_KeyError , "Couldn't find oneof %S " , arg );
572584}
573585
574586static PyObject * PyUpb_DescriptorPool_FindServiceByName (PyObject * _self ,
@@ -578,13 +590,15 @@ static PyObject* PyUpb_DescriptorPool_FindServiceByName(PyObject* _self,
578590 const char * name = PyUpb_VerifyStrData (arg );
579591 if (!name ) return NULL ;
580592
581- const upb_ServiceDef * s = upb_DefPool_FindServiceByName (self -> symtab , name );
593+ const upb_ServiceDef * s = upb_DefPool_FindServiceByNameWithSize (
594+ self -> symtab , name , PyObject_Size (arg ));
582595 if (s == NULL && self -> db ) {
583596 if (!PyUpb_DescriptorPool_TryLoadSymbol (self , arg )) return NULL ;
584- s = upb_DefPool_FindServiceByName (self -> symtab , name );
597+ s = upb_DefPool_FindServiceByNameWithSize (self -> symtab , name ,
598+ PyObject_Size (arg ));
585599 }
586600 if (s == NULL ) {
587- return PyErr_Format (PyExc_KeyError , "Couldn't find service %.200s " , name );
601+ return PyErr_Format (PyExc_KeyError , "Couldn't find service %S " , arg );
588602 }
589603
590604 return PyUpb_ServiceDescriptor_Get (s );
@@ -608,12 +622,13 @@ static PyObject* PyUpb_DescriptorPool_FindMethodByName(PyObject* _self,
608622 upb_DefPool_FindServiceByNameWithSize (self -> symtab , name , parent_size );
609623 }
610624 if (!parent ) goto err ;
611- const upb_MethodDef * m = upb_ServiceDef_FindMethodByName (parent , child );
625+ const upb_MethodDef * m = upb_ServiceDef_FindMethodByNameWithSize (
626+ parent , child , PyObject_Size (arg ) - parent_size - 1 );
612627 if (!m ) goto err ;
613628 return PyUpb_MethodDescriptor_Get (m );
614629
615630err :
616- return PyErr_Format (PyExc_KeyError , "Couldn't find method %.200s " , name );
631+ return PyErr_Format (PyExc_KeyError , "Couldn't find method %S " , arg );
617632}
618633
619634static PyObject * PyUpb_DescriptorPool_FindFileContainingSymbol (PyObject * _self ,
@@ -622,6 +637,9 @@ static PyObject* PyUpb_DescriptorPool_FindFileContainingSymbol(PyObject* _self,
622637
623638 const char * name = PyUpb_VerifyStrData (arg );
624639 if (!name ) return NULL ;
640+ if (PyObject_Size (arg ) != strlen (name )) {
641+ return PyErr_Format (PyExc_KeyError , "Couldn't find symbol %S" , arg );
642+ }
625643
626644 const upb_FileDef * f =
627645 upb_DefPool_FindFileContainingSymbol (self -> symtab , name );
@@ -630,7 +648,7 @@ static PyObject* PyUpb_DescriptorPool_FindFileContainingSymbol(PyObject* _self,
630648 f = upb_DefPool_FindFileContainingSymbol (self -> symtab , name );
631649 }
632650 if (f == NULL ) {
633- return PyErr_Format (PyExc_KeyError , "Couldn't find symbol %.200s " , name );
651+ return PyErr_Format (PyExc_KeyError , "Couldn't find symbol %S " , arg );
634652 }
635653
636654 return PyUpb_FileDescriptor_Get (f );
0 commit comments