Explorar el Código

Avoid unset length_field_coding

ithewei hace 10 meses
padre
commit
41429808f4
Se han modificado 2 ficheros con 8 adiciones y 0 borrados
  1. 3 0
      event/hevent.c
  2. 5 0
      event/unpack.c

+ 3 - 0
event/hevent.c

@@ -849,6 +849,9 @@ void hio_set_unpack(hio_t* io, unpack_setting_t* setting) {
         assert(io->unpack_setting->body_offset >=
                io->unpack_setting->length_field_offset +
                io->unpack_setting->length_field_bytes);
+        if (io->unpack_setting->length_field_coding == 0) {
+            io->unpack_setting->length_field_coding = ENCODE_BY_BIG_ENDIAN;
+        }
     }
 
     // NOTE: unpack must have own readbuf

+ 5 - 0
event/unpack.c

@@ -139,6 +139,11 @@ int hio_unpack_by_length_field(hio_t* io, void* buf, int readbytes) {
                 return -1;
             }
             head_len = setting->body_offset + varint_bytes - setting->length_field_bytes;
+        } else {
+            hloge("Unknown length_field_coding!");
+            io->error = ERR_INVALID_PARAM;
+            hio_close(io);
+            return -1;
         }
         package_len = head_len + body_len + setting->length_adjustment;
         if (remain >= package_len) {