From a00534794eb60d71774a6346a6003432e405b37d Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 29 Nov 2021 00:12:37 +1100 Subject: [PATCH] Another fix for when packets contain binary messages with SOH chars. --- app/Classes/FTN/Message.php | 11 ++++++-- tests/Feature/PacketTest.php | 26 ++++++++++++++++++- tests/Feature/data/test_binary_content-2.pkt | Bin 0 -> 1703 bytes 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 tests/Feature/data/test_binary_content-2.pkt diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index bcdae37..f6f1f66 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -692,9 +692,16 @@ class Message extends FTNBase // If there are is a return in this middle of this line, that means the text message starts after the return // If our message has started, then we'll assume the binary is part of the message. - if (strlen($this->message) || ($retpos != strlen($kl)-1)) { + if (strlen($this->message) || ($retpos !== strlen($kl)-1)) { + + // If there was no return, its part of the message. + if ($retpos === FALSE) { + $this->message .= "\x01".$kl; + continue; + } + // Anything after the origin line is also kludge data. - if (($originpos = strpos($kl,"\r * Origin: "))) { + if ($originpos = strpos($kl,"\r * Origin: ")) { if (! $this->message) { $this->message .= substr($kl,$retpos+1,$originpos-$retpos-1); $this->parseOrigin(substr($kl,$originpos+1)); diff --git a/tests/Feature/PacketTest.php b/tests/Feature/PacketTest.php index 632a60d..61f71a3 100644 --- a/tests/Feature/PacketTest.php +++ b/tests/Feature/PacketTest.php @@ -118,7 +118,31 @@ class PacketTest extends TestCase public function test_packet_parse() { - // This packet has an incorrect zone in the Origin + // This packet has a SOHSOH sequence + $f = new File(__DIR__.'/data/test_binary_content-2.pkt'); + $pkt = Packet::open($f,NULL,FALSE); + + $this->assertEquals(1,$pkt->count()); + + $messages = FALSE; + foreach ($pkt as $msg) { + $messages = TRUE; + + $this->assertNotTrue($msg->isNetmail()); + $this->assertSame('21:1/151 6189F64C',$msg->msgid); + $this->assertSame('db727bd3778ddd457784ada4bf016010',md5($msg->message)); + $this->assertSame('5b627ab5936b0550a97b738f4deff419',md5($msg->message_src)); + $this->assertCount(3,$msg->rogue_path); + $this->assertCount(170,$msg->rogue_seen); + $this->assertContains('3/2744 4/100 106 5/100',$msg->seenby); + $this->assertContains('1/151 100 3/100',$msg->path); + $this->assertCount(11,$msg->seenby); + $this->assertCount(0,$msg->unknown); + } + + $this->assertTrue($messages); + + // This packet has SOH in the message content $f = new File(__DIR__.'/data/test_binary_content.pkt'); $pkt = Packet::open($f,NULL,FALSE); diff --git a/tests/Feature/data/test_binary_content-2.pkt b/tests/Feature/data/test_binary_content-2.pkt new file mode 100644 index 0000000000000000000000000000000000000000..445efbbd6a526d001fe8243f6f9812d993bcf434 GIT binary patch literal 1703 zcmZ{l-)`en5QiPOKwHUz8}5g_*%mda&+&g>EGi+}Rw|`RQ!UF4a^lm(+SsmarzKJz zj2GewcmVjE656n$(TQx&H@`Dye&aN=en0r*iv#PG^`&K52dvMm&-wh-yHr=V!&~3_ znh$@yuU_?b*WEo_MsCMiJ_kO%NyZ9kNI8i6cR}!cw zeiwK{yEh(PUw+s{!a#;99EG9lqt|6zS52E6aR!ksZ{ujqzHFurftSSmqwxqH56J45o zzL=8N3~c+VYNc5LKC(*}f5Y|MwA&1xEKF_K@H^Z7P_1?~*9f%7($&l%N+dYQV^y~c zNwbW-j%mq*c{*)lOxdA}^#0zIcGruloSDJ4YczJblvSCTS)Q3p@;e^$1Q}_n!nBL7 z^0ty<&3Dt7`dFr`Rxa$jG+%ZB~&Zj|?+2M)1sHcn{UC%r#=DD`EMF7u|q zg$HNgI{nN%$l?3E%&N!c-$MRVLD`Z8iSd@ZOa0*Vr zDL4hEf;~A!iXugkqDkS+Q<@YCP?{7?ibh()X*dn%!ntrRjO*>mx!}BT$^~^nJx~wS zL(&8Hkn~_Y7!SsS@nLu)l@H^)dvZRw5AIWePl`{9Pf9>aKuUmQ022@ohzG<2;vumR zxo}@D1PzhnEmt9EgiHh)fksG0#3SMn@d&vHCWeWL$He3P!^WU7SlnT;Xspp#qp?O~ zjm8>{H5zL))@ZEJSfjB;V~bXMavFCuc4+L-*rBmQV}-^FjTIUzG*)P=(Ac1{LA%7U zLA%8H$$Bv;+6C=?`>-NVfy7j+pT>tfyw>9WXPP+9^8`I>fqgPeociC1p*ed~LjSiD z!t?EfAnU#uI^_O$LO?x=`(!fc{qrcitW1YYl=sg$0`a>myLWv$Ip4l4-B{tu_MkTZ GZ2kti{FpKT literal 0 HcmV?d00001