Skip to content

Commit eacd0eb

Browse files
committed
fix: spec-compliant MP ext marker type
It used to serialize MP ext marker type as char, while it is signed integer due to MP specification. On most platforms char is mapped to i8, so no runtime errors were normally seen. It was detected on linux aarch64, where char is u8. Markdown spec [reference](https://github.com/msgpack/msgpack/blob/master/spec.md#ext-format-family).
1 parent 98353c8 commit eacd0eb

File tree

7 files changed

+12
-13
lines changed

7 files changed

+12
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
### Fixed
1313

1414
- Use after free in `fiber::Builder::start_non_joinable` when the fiber exits without yielding.
15+
- Incorrect, off-spec MP Ext type: caused runtime errors on some platforms.
1516

1617
### Deprecated
1718

tarantool/src/datetime.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::ffi::datetime as ffi;
22
use once_cell::sync::Lazy;
33
use serde::{Deserialize, Serialize};
44
use std::fmt::Display;
5-
use std::os::raw::c_char;
65
use time::{Duration, UtcOffset};
76

87
type Inner = time::OffsetDateTime;
@@ -132,7 +131,7 @@ impl serde::Serialize for Datetime {
132131
S: serde::Serializer,
133132
{
134133
#[derive(Serialize)]
135-
struct _ExtStruct<'a>((c_char, &'a serde_bytes::Bytes));
134+
struct _ExtStruct<'a>((i8, &'a serde_bytes::Bytes));
136135

137136
let data = self.as_bytes_tt();
138137
let mut data = data.as_slice();
@@ -149,7 +148,7 @@ impl<'de> serde::Deserialize<'de> for Datetime {
149148
D: serde::Deserializer<'de>,
150149
{
151150
#[derive(Deserialize)]
152-
struct _ExtStruct((c_char, serde_bytes::ByteBuf));
151+
struct _ExtStruct((i8, serde_bytes::ByteBuf));
153152

154153
let _ExtStruct((kind, bytes)) = serde::Deserialize::deserialize(deserializer)?;
155154

tarantool/src/decimal.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ mod tarantool_decimal {
438438
S: serde::Serializer,
439439
{
440440
#[derive(Serialize)]
441-
struct _ExtStruct((std::os::raw::c_char, serde_bytes::ByteBuf));
441+
struct _ExtStruct((i8, serde_bytes::ByteBuf));
442442

443443
let data = unsafe {
444444
let len = ffi::decimal_len(&self.inner) as usize;
@@ -457,7 +457,7 @@ mod tarantool_decimal {
457457
D: serde::Deserializer<'de>,
458458
{
459459
#[derive(Deserialize)]
460-
struct _ExtStruct((std::os::raw::c_char, serde_bytes::ByteBuf));
460+
struct _ExtStruct((i8, serde_bytes::ByteBuf));
461461

462462
match serde::Deserialize::deserialize(deserializer)? {
463463
_ExtStruct((ffi::MP_DECIMAL, bytes)) => {
@@ -1142,7 +1142,7 @@ mod standalone_decimal {
11421142
S: serde::Serializer,
11431143
{
11441144
#[derive(serde::Serialize)]
1145-
struct _ExtStruct((std::os::raw::c_char, serde_bytes::ByteBuf));
1145+
struct _ExtStruct((i8, serde_bytes::ByteBuf));
11461146

11471147
let data = {
11481148
let mut data = vec![];
@@ -1162,7 +1162,7 @@ mod standalone_decimal {
11621162
{
11631163
use serde::de::Error;
11641164
#[derive(serde::Deserialize)]
1165-
struct _ExtStruct((std::os::raw::c_char, serde_bytes::ByteBuf));
1165+
struct _ExtStruct((i8, serde_bytes::ByteBuf));
11661166

11671167
match serde::Deserialize::deserialize(deserializer)? {
11681168
_ExtStruct((ffi::MP_DECIMAL, bytes)) => {

tarantool/src/ffi/datetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub const MP_DATETIME: std::os::raw::c_char = 4;
1+
pub const MP_DATETIME: i8 = 4;
22

33
#[repr(C)]
44
#[derive(Debug, Copy, Clone)]

tarantool/src/ffi/decimal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Hash for decNumber {
2828
pub const DECDPUN: usize = 3;
2929
pub const DECNUMUNITS: u32 = 13;
3030
pub const DECIMAL_MAX_DIGITS: u32 = 38;
31-
pub const MP_DECIMAL: c_char = 1;
31+
pub const MP_DECIMAL: i8 = 1;
3232

3333
crate::define_dlsym_reloc! {
3434
/// Return decimal precision,

tarantool/src/ffi/uuid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub const MP_UUID: std::os::raw::c_char = 2;
1+
pub const MP_UUID: i8 = 2;
22

33
#[repr(C)]
44
#[derive(Copy, Clone)]

tarantool/src/uuid.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::ffi::uuid as ffi;
2-
use std::os::raw::c_char;
32

43
pub use ::uuid::{adapter, Error};
54
use serde::{Deserialize, Serialize};
@@ -217,7 +216,7 @@ impl serde::Serialize for Uuid {
217216
S: serde::Serializer,
218217
{
219218
#[derive(Serialize)]
220-
struct _ExtStruct((c_char, serde_bytes::ByteBuf));
219+
struct _ExtStruct((i8, serde_bytes::ByteBuf));
221220

222221
let data = self.as_bytes();
223222
_ExtStruct((ffi::MP_UUID, serde_bytes::ByteBuf::from(data as &[_]))).serialize(serializer)
@@ -230,7 +229,7 @@ impl<'de> serde::Deserialize<'de> for Uuid {
230229
D: serde::Deserializer<'de>,
231230
{
232231
#[derive(Deserialize)]
233-
struct _ExtStruct((c_char, serde_bytes::ByteBuf));
232+
struct _ExtStruct((i8, serde_bytes::ByteBuf));
234233

235234
let _ExtStruct((kind, bytes)) = serde::Deserialize::deserialize(deserializer)?;
236235

0 commit comments

Comments
 (0)