* [pbs-devel] [PATCH proxmox 1/3] schema: use i64 for minimum / maximum / default integer values
@ 2025-01-29 10:42 Stefan Hanreich
2025-01-29 10:42 ` [pbs-devel] [PATCH proxmox 2/3] pbs-api-types: fix values for integer schemas Stefan Hanreich
2025-01-29 10:42 ` [pbs-devel] [PATCH proxmox-backup 3/3] api: change integer schema parameters to i64 Stefan Hanreich
0 siblings, 2 replies; 3+ messages in thread
From: Stefan Hanreich @ 2025-01-29 10:42 UTC (permalink / raw)
To: pbs-devel
IntegerSchema used isize for the minimum / maximum parameters. On 32
bit targets (wasm for instance) API defintions with minimum / maximum
sizes outside the i32 range would fail.
This also changes the u64 deserialize to fail if it encounters a value
that cannot be represented as i64 instead of simply casting it to i64
and moving on.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
proxmox-schema/src/de/mod.rs | 3 +--
proxmox-schema/src/de/verify.rs | 13 ++++++++-----
proxmox-schema/src/schema.rs | 18 +++++++++---------
3 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/proxmox-schema/src/de/mod.rs b/proxmox-schema/src/de/mod.rs
index eca835e3..1f14503e 100644
--- a/proxmox-schema/src/de/mod.rs
+++ b/proxmox-schema/src/de/mod.rs
@@ -173,8 +173,7 @@ impl<'de> de::Deserializer<'de> for SchemaDeserializer<'de, '_> {
.map_err(|_| Error::msg(format!("not a boolean: {:?}", self.input)))?,
),
Schema::Integer(schema) => {
- // FIXME: isize vs explicit i64, needs fixing in schema check_constraints api
- let value: isize = self
+ let value: i64 = self
.input
.parse()
.map_err(|_| Error::msg(format!("not an integer: {:?}", self.input)))?;
diff --git a/proxmox-schema/src/de/verify.rs b/proxmox-schema/src/de/verify.rs
index 67a8c9e8..917f956b 100644
--- a/proxmox-schema/src/de/verify.rs
+++ b/proxmox-schema/src/de/verify.rs
@@ -170,7 +170,7 @@ impl<'de> de::Visitor<'de> for Visitor {
fn visit_i64<E: de::Error>(self, v: i64) -> Result<Self::Value, E> {
match self.0 {
- Schema::Integer(schema) => match schema.check_constraints(v as isize) {
+ Schema::Integer(schema) => match schema.check_constraints(v) {
Ok(()) => Ok(Verifier),
Err(err) => Err(E::custom(err)),
},
@@ -180,10 +180,13 @@ impl<'de> de::Visitor<'de> for Visitor {
fn visit_u64<E: de::Error>(self, v: u64) -> Result<Self::Value, E> {
match self.0 {
- Schema::Integer(schema) => match schema.check_constraints(v as isize) {
- Ok(()) => Ok(Verifier),
- Err(err) => Err(E::custom(err)),
- },
+ Schema::Integer(schema) => {
+ let val = v.try_into().or_else(|err| Err(E::custom(err)))?;
+ match schema.check_constraints(val) {
+ Ok(()) => Ok(Verifier),
+ Err(err) => Err(E::custom(err)),
+ }
+ }
_ => Err(E::invalid_type(Unexpected::Unsigned(v), &self)),
}
}
diff --git a/proxmox-schema/src/schema.rs b/proxmox-schema/src/schema.rs
index 3448112b..3090da09 100644
--- a/proxmox-schema/src/schema.rs
+++ b/proxmox-schema/src/schema.rs
@@ -228,11 +228,11 @@ impl BooleanSchema {
pub struct IntegerSchema {
pub description: &'static str,
/// Optional minimum.
- pub minimum: Option<isize>,
+ pub minimum: Option<i64>,
/// Optional maximum.
- pub maximum: Option<isize>,
+ pub maximum: Option<i64>,
/// Optional default.
- pub default: Option<isize>,
+ pub default: Option<i64>,
}
impl IntegerSchema {
@@ -250,17 +250,17 @@ impl IntegerSchema {
self
}
- pub const fn default(mut self, default: isize) -> Self {
+ pub const fn default(mut self, default: i64) -> Self {
self.default = Some(default);
self
}
- pub const fn minimum(mut self, minimum: isize) -> Self {
+ pub const fn minimum(mut self, minimum: i64) -> Self {
self.minimum = Some(minimum);
self
}
- pub const fn maximum(mut self, maximum: isize) -> Self {
+ pub const fn maximum(mut self, maximum: i64) -> Self {
self.maximum = Some(maximum);
self
}
@@ -269,7 +269,7 @@ impl IntegerSchema {
Schema::Integer(self)
}
- pub fn check_constraints(&self, value: isize) -> Result<(), Error> {
+ pub fn check_constraints(&self, value: i64) -> Result<(), Error> {
if let Some(minimum) = self.minimum {
if value < minimum {
bail!(
@@ -296,7 +296,7 @@ impl IntegerSchema {
/// Verify JSON value using an `IntegerSchema`.
pub fn verify_json(&self, data: &Value) -> Result<(), Error> {
if let Some(value) = data.as_i64() {
- self.check_constraints(value as isize)
+ self.check_constraints(value)
} else {
bail!("Expected integer value.");
}
@@ -1235,7 +1235,7 @@ impl Schema {
Value::Bool(res)
}
Schema::Integer(integer_schema) => {
- let res: isize = value_str.parse()?;
+ let res: i64 = value_str.parse()?;
integer_schema.check_constraints(res)?;
Value::Number(res.into())
}
--
2.39.5
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pbs-devel] [PATCH proxmox 2/3] pbs-api-types: fix values for integer schemas
2025-01-29 10:42 [pbs-devel] [PATCH proxmox 1/3] schema: use i64 for minimum / maximum / default integer values Stefan Hanreich
@ 2025-01-29 10:42 ` Stefan Hanreich
2025-01-29 10:42 ` [pbs-devel] [PATCH proxmox-backup 3/3] api: change integer schema parameters to i64 Stefan Hanreich
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hanreich @ 2025-01-29 10:42 UTC (permalink / raw)
To: pbs-devel
Because of the change from isize to i64 some casts have to be adjusted
so the types for the maximum / default values are correct again.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
pbs-api-types/src/datastore.rs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs
index ddd8d3c6..36a3f093 100644
--- a/pbs-api-types/src/datastore.rs
+++ b/pbs-api-types/src/datastore.rs
@@ -92,14 +92,14 @@ pub const BACKUP_NAMESPACE_SCHEMA: Schema = StringSchema::new("Namespace.")
pub const NS_MAX_DEPTH_SCHEMA: Schema =
IntegerSchema::new("How many levels of namespaces should be operated on (0 == no recursion)")
.minimum(0)
- .maximum(MAX_NAMESPACE_DEPTH as isize)
- .default(MAX_NAMESPACE_DEPTH as isize)
+ .maximum(MAX_NAMESPACE_DEPTH as i64)
+ .default(MAX_NAMESPACE_DEPTH as i64)
.schema();
pub const NS_MAX_DEPTH_REDUCED_SCHEMA: Schema =
IntegerSchema::new("How many levels of namespaces should be operated on (0 == no recursion, empty == automatic full recursion, namespace depths reduce maximum allowed value)")
.minimum(0)
- .maximum(MAX_NAMESPACE_DEPTH as isize)
+ .maximum(MAX_NAMESPACE_DEPTH as i64)
.schema();
pub const DATASTORE_SCHEMA: Schema = StringSchema::new("Datastore name.")
--
2.39.5
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pbs-devel] [PATCH proxmox-backup 3/3] api: change integer schema parameters to i64
2025-01-29 10:42 [pbs-devel] [PATCH proxmox 1/3] schema: use i64 for minimum / maximum / default integer values Stefan Hanreich
2025-01-29 10:42 ` [pbs-devel] [PATCH proxmox 2/3] pbs-api-types: fix values for integer schemas Stefan Hanreich
@ 2025-01-29 10:42 ` Stefan Hanreich
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hanreich @ 2025-01-29 10:42 UTC (permalink / raw)
To: pbs-devel
The type for the minimum / maximum / default values for integer
schemas has changed to i64 (from isize). Fix all call sites that are
converting to isize to convert to i64 instead.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
pbs-tape/src/bin/pmt.rs | 6 +++---
proxmox-backup-client/src/main.rs | 2 +-
pxar-bin/src/main.rs | 6 +++---
src/api2/backup/upload_chunk.rs | 15 ++++++---------
4 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/pbs-tape/src/bin/pmt.rs b/pbs-tape/src/bin/pmt.rs
index 9e39dbe1..685fa835 100644
--- a/pbs-tape/src/bin/pmt.rs
+++ b/pbs-tape/src/bin/pmt.rs
@@ -29,17 +29,17 @@ use pbs_tape::{
pub const FILE_MARK_COUNT_SCHEMA: Schema = IntegerSchema::new("File mark count.")
.minimum(1)
- .maximum(i32::MAX as isize)
+ .maximum(i32::MAX as i64)
.schema();
pub const FILE_MARK_POSITION_SCHEMA: Schema = IntegerSchema::new("File mark position (0 is BOT).")
.minimum(0)
- .maximum(i32::MAX as isize)
+ .maximum(i32::MAX as i64)
.schema();
pub const RECORD_COUNT_SCHEMA: Schema = IntegerSchema::new("Record count.")
.minimum(1)
- .maximum(i32::MAX as isize)
+ .maximum(i32::MAX as i64)
.schema();
pub const DRIVE_OPTION_SCHEMA: Schema =
diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs
index 589a097b..3666a313 100644
--- a/proxmox-backup-client/src/main.rs
+++ b/proxmox-backup-client/src/main.rs
@@ -718,7 +718,7 @@ fn spawn_catalog_upload(
type: Integer,
description: "Max number of entries to hold in memory.",
optional: true,
- default: pbs_client::pxar::ENCODER_MAX_ENTRIES as isize,
+ default: pbs_client::pxar::ENCODER_MAX_ENTRIES as i64,
},
"dry-run": {
type: Boolean,
diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs
index 7dff1e38..d0742f6b 100644
--- a/pxar-bin/src/main.rs
+++ b/pxar-bin/src/main.rs
@@ -330,9 +330,9 @@ fn extract_archive(
"entries-max": {
description: "Max number of entries loaded at once into memory",
optional: true,
- default: ENCODER_MAX_ENTRIES as isize,
+ default: ENCODER_MAX_ENTRIES as i64,
minimum: 0,
- maximum: isize::MAX,
+ maximum: i64::MAX,
},
"payload-output": {
description: "'ppxar' payload output data file to create split archive.",
@@ -354,7 +354,7 @@ async fn create_archive(
no_fifos: bool,
no_sockets: bool,
exclude: Option<Vec<String>>,
- entries_max: isize,
+ entries_max: i64,
payload_output: Option<String>,
) -> Result<(), Error> {
let patterns = {
diff --git a/src/api2/backup/upload_chunk.rs b/src/api2/backup/upload_chunk.rs
index 20259660..ca22efbd 100644
--- a/src/api2/backup/upload_chunk.rs
+++ b/src/api2/backup/upload_chunk.rs
@@ -133,10 +133,9 @@ pub const API_METHOD_UPLOAD_FIXED_CHUNK: ApiMethod = ApiMethod::new(
"encoded-size",
false,
&IntegerSchema::new("Encoded chunk size.")
- .minimum((std::mem::size_of::<DataBlobHeader>() as isize) + 1)
+ .minimum((std::mem::size_of::<DataBlobHeader>() as i64) + 1)
.maximum(
- 1024 * 1024 * 16
- + (std::mem::size_of::<EncryptedDataBlobHeader>() as isize)
+ 1024 * 1024 * 16 + (std::mem::size_of::<EncryptedDataBlobHeader>() as i64)
)
.schema()
),
@@ -202,10 +201,9 @@ pub const API_METHOD_UPLOAD_DYNAMIC_CHUNK: ApiMethod = ApiMethod::new(
"encoded-size",
false,
&IntegerSchema::new("Encoded chunk size.")
- .minimum((std::mem::size_of::<DataBlobHeader>() as isize) + 1)
+ .minimum((std::mem::size_of::<DataBlobHeader>() as i64) + 1)
.maximum(
- 1024 * 1024 * 16
- + (std::mem::size_of::<EncryptedDataBlobHeader>() as isize)
+ 1024 * 1024 * 16 + (std::mem::size_of::<EncryptedDataBlobHeader>() as i64)
)
.schema()
),
@@ -290,10 +288,9 @@ pub const API_METHOD_UPLOAD_BLOB: ApiMethod = ApiMethod::new(
"encoded-size",
false,
&IntegerSchema::new("Encoded blob size.")
- .minimum(std::mem::size_of::<DataBlobHeader>() as isize)
+ .minimum(std::mem::size_of::<DataBlobHeader>() as i64)
.maximum(
- 1024 * 1024 * 16
- + (std::mem::size_of::<EncryptedDataBlobHeader>() as isize)
+ 1024 * 1024 * 16 + (std::mem::size_of::<EncryptedDataBlobHeader>() as i64)
)
.schema()
)
--
2.39.5
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-29 10:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-29 10:42 [pbs-devel] [PATCH proxmox 1/3] schema: use i64 for minimum / maximum / default integer values Stefan Hanreich
2025-01-29 10:42 ` [pbs-devel] [PATCH proxmox 2/3] pbs-api-types: fix values for integer schemas Stefan Hanreich
2025-01-29 10:42 ` [pbs-devel] [PATCH proxmox-backup 3/3] api: change integer schema parameters to i64 Stefan Hanreich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox