gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 279 forks source link

(Binary) - 4096 OODBean::__toString() must return string value #709

Closed ccgintranet closed 5 years ago

ccgintranet commented 5 years ago

Hello,

I am using openssl_encrypt with OPENSSL_RAW_DATA in order to store ciphertext as raw binary in the database however Redbean seems to be having issues with it.

Is there a workaround for this?

Critical Failure (4096): on line [148] in file [D:\DEVELOPMENT\Microservices\referral-system\referral_service\www\vendor\gabordemooij\redbean\RedBeanPHP\Repository.php] Message: [Method RedBeanPHP\OODBBean::__toString() must return a string value]

Kind Regards

gabordemooij commented 5 years ago

You could try to use base64 instead but I'll look into this issue.

gabordemooij commented 5 years ago

Thanks for reporting.

gabordemooij commented 5 years ago

Can you give me an example bean or value maybe?

ccgintranet commented 5 years ago

Hello,

Thank you for getting back to us so quickly. We unfortunately cannot base64 encode this as other services we have work on raw byte streams.

An example bean may look like the following (note the binary value for risk that matches a LONGBLOB field in MySQL 5.7

`RedBeanPHP\OODBBean {#91

properties: array:6 [

"id" => 0
"risk" => b"""
  yF/ͽ=.\x14╦.\x10\x15æ\x1Ca┤â5\x1E\x14«Ó\x17D«ÜùJoè%ñ$~;6%J\x7F÷\x1Eùé¨õZðj‗Ö║¬(:\rñA\x16Â[;■C\x08¦═\x19▓┼NØÄ\fc\n
  V"%\n
  þq"(\x06h§Ç├qÅú3%\x05\x02>N▓+ÔOª£Rû@*\n
  y®~┌(Ècô┬kË╗k>^\vº\x1DƒÔ£ýu▒║wG_â=┌¯ı®\x0ECÀ=│Å╣(c┌CQ│Ø?/Ä7\x1C¿\x18▒Û6\x034\x17ı\e\x12!\x11ýÙü\r'³q&\x11xLoEÁltö|\x10\x06*ÿSå\x02╣ðìMúüúåy╬Ù┴\x10┐\eb├»×ü\ë¼a¤~ö┤5\x15i¯■î┼M\x00╦2Ù\x06Ù┤Ýzº\x19nÙ\t\x03\t±N\x04n,àèl┤,Ú┴ÞBDQ\rHl\x1ACÄ\v~þrÃDä█y²sc=Ñû÷Õ╦Ìö­úëC+\x02\x7FàSªÑ‗)▀r▒¦\x1C\x03\x08¬º"ó\x1CNwÎõ]╔íç\x1D3R×5\x15ïè)\x19■R\x0EI#r>\x1D¶á2l2\x18Æg Ѽ¢\x11ðqåÝÛ╠t÷à\x1DÍlÏà"ô6רsÝýg\x11oAeúÜA\x04¬C¡Ûj*\x1CVFfÎ颃YÌ(È9íN\r\­Ý¢Ì×ådÆ+R°å£ãÍã\x02░^\x1AI\x01¼¹ªª\x00·pç┌¯l}g#y\x02╔TêÕÑÏ8¡¥Ót\x19q╣u\x0E:àEró[P\x06\x04p¡]×─tôë_y\x18F¹þ$\r!FÉÞ!╔køu║y¶»Rw·åÓ\x08e│È\x02?:QÈqâ\x03ü┼\x07µÏ-²rü\x1A\x1CáØ$~ûu/OcQ´ù\x07¶ó┐\x06º ¤\t Ã\x0E"BÄäÏ╚®Ìª»c¾1ÐÅ\¯ı\x06º\x07a\x02«.\v+\x01*=?»;kKË\x0E\x14&<5½TºÖ\x13\e│Ob|Ó°o1┘·\x10·7´╝ú▀%ÈH¡Ù³udÑ\v1Ý\f\x0FÆ\x07║ÉF×h╠2r.a·╦G#×Q\x14\x0F|7Þ­gàüZ,LJ²l^▀ë═ÿßÏ▓r9 ËÖ$z]÷Î\x10)ñÉ\x12ð▄+>l\v@Ú\x02ÿÿ[░─±NÃd0F¢4Á\x060ƒÈ«­\rieÚ.\x11╗6üã6Ñ\tì\vËè¯Ëgýı\x07þü\x175È\x14╣ÙÀ<╔"l─'G\x1C@üð|¤á\x19Lbp2Í╚ÛG²À©>Ú┐¿s\x1D¨\x1Fà>0L$E³¹ù¢³\x00┼TªZÂQ\vGOä¹øäþãX\x1FNÑß]táòÀÍ\fcûìÜÖûRÑûoij\x12UC¦©\x0EaÀxyTïÄö▄3°ÌÀ║GpR ÷░└¨\x16l±ç{Ô╩:vÓVG╝°╔©}íW¾¢²\x11í\x00h█╔±E\x16/#6É<Ê╠ä╠E\x03mu\n
  sZ⿹é▄³U╚\x17J\x05×,"\eÔ]ëAÞzõx\n
  º┌│LA▀JO,«,ƒ?Ô¹ÁÒÓxûf´í_B2Ä­ÉܹªrU¿█9┘á|14Þ&U\x0E÷:\x13÷"\x12hãÙjÀ(ƒY¶ý9I³j`╝Öp┬úgÄ 2^\x10Ä©l\x03¤e\x04\x15 "®ø_´\x04Ý{░Cz:Y┴Îl\x1Dp$\x7Fñ8ØÞ\x16½`:8zIL£║O<\x1C\x0F\trÚ×t°\FÎWSaA┤õ.ØŽ&ïG>Z├\x02pëèf\n
  "Q\x06╝2Ôb\x11ÐÜóe5ªX#I¥\x11ó▓\x1EýKQ\x1FÒSÿƒu¿═|k▒\x19CþòÞstÜ_¥×ÍjèÎì®G§¡¼├C│u7½ÔÕ;Ù‗åRÀ ©gj\x04~W┼╚ãÓ\x1C╔¾ßÀµ±╩`YSÐ┌õ3\x15XöXÚÆëGü\x1Fõ╠╚÷fI┼\t&Ø╦│\x04kEÕG\x14\x0F\x19\x7F░ëV»¼¹a|Ln²\x1CëÔSð¡\x17│▀&À╗þÊ´'}þ\x1EYí\x0E\x12´Å§░╣õ\x1A\x0F\n
  nOý©®█V°\x15¬³\x05J®Üô\f¨\x03╔5\x0FïÍEÁü%\x1CàbØn\x1Cß<©,\x7F\x07áìJ\x15µñþƒZUÁÛlqj└▓°á\x1Cà╦×\x1DýQ|\x00½g÷P\x11\x06¹æ"À\x16·┼\x03È;\x06░ SYı─giÐBãëÄÞÐüf\x1A\x15▀│p█╬ª}Éqä\f71&h]#MW2\v«sz2┌Û╝╩\n
  b(f,Á┴ú¡A╚N<\x11²:{B├ã═áúlÆ4;÷§\x1C]1\x1A┼\x01Ú\x01ÒËì\O2Kû|ì;ÍÉíVQPáPâà ¼½ã¨\f9║e‗æ\x01ÎÂ\x1F═f ½Ù±vŽÂ\x19¯┬@+3t▄¬NÛeë\x04Ä©4Ý╬±Û■("Ì9┤¥ænhGùÛ\ñF´xw¶­y═¶\n
  øT/\fÛ\x04\x04\n
  OÁ\x1Af┘§\x16§òÀ¨¼lüç\x12Óâ╬┼I&░zaAV\x15▀ÙÿkV1\f,)©,-MYh5)òıË╩Nëï\x1EÎPF¤H3Í╠8¥Gà|█ð╚£è:ÝrE¸¡n\tȲ┌ãbÿÏì\x10\x1C£¿Å╚\x11\x1DéY\x14zJ¥ÖG®\x07ê\¼Ï├▀6æï╦^\x00a╩í╣Uè\x05¡_°¶▒\x02\x02`GBvS█â¦þQouÁÞD¡╦Vá|ñZ\x14\x0Eëm¦\x12}B°ÇÏÂ9¿▄õS┴f═Õ│Ð└*▒L└qâ,$3®Lð_A\ã©─╔õR\x02ú╬█ÏÀ\x7F┌Û\x1ArAµ*È~µ²ò ¾-\x00¬e'Q·'1õm\x11ìÂf°n\v└╦TYΦÖþÁl£,\x17_\x1Dë2\x1AÜ\x10Ç¿Êm@\x06ùı>ø1Ó\x04`>h¦┴k╔I?=ÆÎf?/uøñÇç\fV\x0E¿4xO}ÁNlBF·╬6©╔©½ÐÆp╔▄4°Ò¼╣;e#╩\x1FSR(Y¤²┼"\x17:±·ô2û½U"i\x08ëõ┴%:ôı8ð1±wC\x00ı#×Âì─╠¸Cðu▒\x01é7àiÑÐs½ºÙ¥└]v(« ╠cP░§ÆÂy\x0E▒■tÈSß\n
  └¤¯û}QP«\x12╣ÜBwÿ0\x0EI4▓\x059)*Ã\x13\x00¹\x0EÀ«─Ùg\x14\x03lÂË)\x13øNa▒╝\x11uG\x06ƒ^ìÈ5õ!n
  """
"requester" => 1
"done" => "N"
"inserted_at" => "2019-05-13 10:45:22"
"updated_at" => "2019-05-13 10:45:22"

]

__info: array:7 [

"type" => "risks"
"sys.id" => "id"
"sys.orig" => array:1 [
  "id" => 0
]
"tainted" => true
"changed" => true
"changelist" => array:5 [
  0 => "risk"
  1 => "requester"
  2 => "done"
  3 => "inserted_at"
  4 => "updated_at"
]
"model" => App\Models\Risks {#254
  #bean: RedBeanPHP\OODBBean {#91}
}

]

beanHelper: RedBeanPHP\BeanHelper\SimpleFacadeBeanHelper {#424}

fetchType: null

withSql: ""

withParams: []

aliasName: null

via: null

noLoad: false

all: false

}`

Kind Regards,

gabordemooij commented 5 years ago

This seems to be an issue with PHP's toString() in general, it cannot return raw bytes. Have you tried to override the toString() method in a Model? You have to circumvent the toString() method from PHP I guess...

Lynesth commented 5 years ago

Hey there,

Didn't get to dig deep into this but I think that according to #528 and https://github.com/gabordemooij/redbean/commit/4a562040778e6aea38cb88ac130f27c76debd583 you made the setEnforceUTF8Encoding() function as a fix for this exact issue 2 years ago.

Maybe we could check if a value contains raw bytes (non printable characters maybe ?) and encode it on the fly or something ? I guess overriding the __toString() function would work to of course.

gabordemooij commented 5 years ago

I dont think that is what they want though... (they do not want base64 either, UTF-8 is just another encoding) anyway this issue lacks some context. I think this just a PHP limitation....