Kontinuation commented on code in PR #695: URL: https://github.com/apache/sedona-db/pull/695#discussion_r2932263632
########## c/sedona-gdal/src/vsi.rs: ########## @@ -0,0 +1,186 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Ported (and contains copied code) from georust/gdal: +//! <https://github.com/georust/gdal/blob/v0.19.0/src/vsi.rs>. +//! Original code is licensed under MIT. +//! +//! GDAL Virtual File System (VSI) wrappers. + +use std::ffi::CString; + +use crate::errors::{GdalError, Result}; +use crate::gdal_api::{call_gdal_api, GdalApi}; + +/// Creates a new VSI in-memory file from a given buffer. +/// +/// The data is copied into GDAL-allocated memory (via `VSIMalloc`) so that +/// GDAL can safely free it with `VSIFree` when ownership is taken. +pub fn create_mem_file(api: &'static GdalApi, file_name: &str, data: &[u8]) -> Result<()> { Review Comment: The same function in georust/gdal is defined as ```rust pub fn create_mem_file(api: &'static GdalApi, file_name: &str, data: &[u8]) -> Result<()> ``` See [src/vsi.rs#L40-L70](https://github.com/georust/gdal/blob/500753686b27c982cfd20ad4ab459b0cfafdba79/src/vsi.rs#L40-L70). This can be super problematic. The mem file buffer is allocated by Rust allocator and will be freed by the native GDAL library. There's no guarantee that Rust and GDAL will use the same or compatible allocator, Deallocation failures or memory corruption could happen when the mem file was dropped. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
