mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 03:50:57 +01:00
fixed utf8 bug, which sometimes lead to z85 handling of pure binary data
This commit is contained in:
@@ -8,6 +8,7 @@ extern "C" {
|
|||||||
#include "pcp/config.h"
|
#include "pcp/config.h"
|
||||||
#include "pcp/base85.h"
|
#include "pcp/base85.h"
|
||||||
#include "pcp/buffer.h"
|
#include "pcp/buffer.h"
|
||||||
|
#include "pcp/config.h"
|
||||||
#include "pcp/crypto.h"
|
#include "pcp/crypto.h"
|
||||||
#include "pcp/defines.h"
|
#include "pcp/defines.h"
|
||||||
#include "pcp/digital_crc32.h"
|
#include "pcp/digital_crc32.h"
|
||||||
|
|||||||
@@ -331,6 +331,7 @@ void ps_determine(Pcpstream *stream) {
|
|||||||
|
|
||||||
/* check if it's binary or not */
|
/* check if it's binary or not */
|
||||||
if(_buffer_is_binary(buf, got) == 0) {
|
if(_buffer_is_binary(buf, got) == 0) {
|
||||||
|
|
||||||
/* not binary, it's armored */
|
/* not binary, it's armored */
|
||||||
stream->armor = 1;
|
stream->armor = 1;
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ size_t _buffer_is_binary(byte *buf, size_t len) {
|
|||||||
for (pos=1; pos<len; ++pos) {
|
for (pos=1; pos<len; ++pos) {
|
||||||
if(buf[pos] == '\0' || (buf[pos] != '\r' && buf[pos] != '\n' && isprint(buf[pos]) == 0)) {
|
if(buf[pos] == '\0' || (buf[pos] != '\r' && buf[pos] != '\n' && isprint(buf[pos]) == 0)) {
|
||||||
/* it's probably a binary char */
|
/* it's probably a binary char */
|
||||||
|
|
||||||
/* check for utf8 */
|
/* check for utf8 */
|
||||||
wide[0] = buf[pos];
|
wide[0] = buf[pos];
|
||||||
for(i=1; i<3; i++) {
|
for(i=1; i<3; i++) {
|
||||||
@@ -112,20 +111,23 @@ size_t _buffer_is_binary(byte *buf, size_t len) {
|
|||||||
if(is_utf8(wide) > 1) {
|
if(is_utf8(wide) > 1) {
|
||||||
pos += i; /* jump over the utf we already found */
|
pos += i; /* jump over the utf we already found */
|
||||||
utf = 1;
|
utf = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
memset(wide, 0, 4);
|
||||||
|
|
||||||
if(utf == 1) {
|
if(utf == 1) {
|
||||||
/* it's a utf8 char, continue checking, reset wide */
|
/* it's a utf8 char, continue checking, reset wide */
|
||||||
memset(wide, 0, 4);
|
utf = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break; /* if we reach this, then it's binary and not utf8, stop checking */
|
break; /* if we reach this, then it's binary and not utf8, stop checking */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pos < len)
|
if(pos < len)
|
||||||
return pos; /* binary */
|
return pos; /* binary */
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user