Skip to content

Commit e60ccb2

Browse files
Renyi Zhaosdroege
authored andcommitted
pango: Fix out-of-bounds access in itemize functions
1 parent e5e2f49 commit e60ccb2

File tree

3 files changed

+66
-48
lines changed

3 files changed

+66
-48
lines changed

pango/Gir.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,13 @@ status = "generate"
9696
ignore = true
9797
[[object.function]]
9898
name = "itemize"
99+
manual = true
99100
[[object.function.parameter]]
100101
name = "cached_iter"
101102
const = true
102103
[[object.function]]
103104
name = "itemize_with_base_dir"
105+
manual = true
104106
[[object.function.parameter]]
105107
name = "cached_iter"
106108
const = true

pango/src/auto/functions.rs

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
// from gir-files (https://github.com/gtk-rs/gir-files)
33
// DO NOT EDIT
44

5-
use crate::{
6-
ffi, AttrIterator, AttrList, Context, Direction, Item, Stretch, Style, Variant, Weight,
7-
};
5+
use crate::{ffi, AttrList, Direction, Stretch, Style, Variant, Weight};
86
use glib::translate::*;
97

108
//#[cfg_attr(feature = "v1_44", deprecated = "Since 1.44")]
@@ -56,50 +54,6 @@ pub fn is_zero_width(ch: char) -> bool {
5654
unsafe { from_glib(ffi::pango_is_zero_width(ch.into_glib())) }
5755
}
5856

59-
#[doc(alias = "pango_itemize")]
60-
pub fn itemize(
61-
context: &Context,
62-
text: &str,
63-
start_index: i32,
64-
length: i32,
65-
attrs: &AttrList,
66-
cached_iter: Option<&AttrIterator>,
67-
) -> Vec<Item> {
68-
unsafe {
69-
FromGlibPtrContainer::from_glib_full(ffi::pango_itemize(
70-
context.to_glib_none().0,
71-
text.to_glib_none().0,
72-
start_index,
73-
length,
74-
attrs.to_glib_none().0,
75-
mut_override(cached_iter.to_glib_none().0),
76-
))
77-
}
78-
}
79-
80-
#[doc(alias = "pango_itemize_with_base_dir")]
81-
pub fn itemize_with_base_dir(
82-
context: &Context,
83-
base_dir: Direction,
84-
text: &str,
85-
start_index: i32,
86-
length: i32,
87-
attrs: &AttrList,
88-
cached_iter: Option<&AttrIterator>,
89-
) -> Vec<Item> {
90-
unsafe {
91-
FromGlibPtrContainer::from_glib_full(ffi::pango_itemize_with_base_dir(
92-
context.to_glib_none().0,
93-
base_dir.into_glib(),
94-
text.to_glib_none().0,
95-
start_index,
96-
length,
97-
attrs.to_glib_none().0,
98-
mut_override(cached_iter.to_glib_none().0),
99-
))
100-
}
101-
}
102-
10357
#[doc(alias = "pango_markup_parser_finish")]
10458
pub fn markup_parser_finish(
10559
context: &glib::MarkupParseContext,

pango/src/functions.rs

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{ffi::c_char, ptr};
66
pub use crate::auto::functions::*;
77
#[cfg(feature = "v1_44")]
88
use crate::ShapeFlags;
9-
use crate::{ffi, Analysis, GlyphString, Item};
9+
use crate::{ffi, Analysis, AttrIterator, AttrList, Context, Direction, GlyphString, Item};
1010

1111
#[doc(alias = "pango_reorder_items")]
1212
pub fn reorder_items(logical_items: &glib::List<Item>) -> glib::List<Item> {
@@ -93,3 +93,65 @@ pub fn extents_to_pixels(
9393
ffi::pango_extents_to_pixels(inclusive.to_glib_none_mut().0, nearest.to_glib_none_mut().0);
9494
}
9595
}
96+
97+
#[doc(alias = "pango_itemize")]
98+
pub fn itemize(
99+
context: &Context,
100+
text: &str,
101+
start_index: i32,
102+
length: i32,
103+
attrs: &AttrList,
104+
cached_iter: Option<&AttrIterator>,
105+
) -> Vec<Item> {
106+
let total_length = text.len() as i32;
107+
assert!(
108+
start_index >= 0 && start_index < total_length,
109+
"start_index is out of range"
110+
);
111+
assert!(
112+
length >= 0 && start_index.checked_add(length).unwrap() < total_length,
113+
"start_index + length is out of range"
114+
);
115+
unsafe {
116+
FromGlibPtrContainer::from_glib_full(ffi::pango_itemize(
117+
context.to_glib_none().0,
118+
text.to_glib_none().0,
119+
start_index,
120+
length,
121+
attrs.to_glib_none().0,
122+
mut_override(cached_iter.to_glib_none().0),
123+
))
124+
}
125+
}
126+
127+
#[doc(alias = "pango_itemize_with_base_dir")]
128+
pub fn itemize_with_base_dir(
129+
context: &Context,
130+
base_dir: Direction,
131+
text: &str,
132+
start_index: i32,
133+
length: i32,
134+
attrs: &AttrList,
135+
cached_iter: Option<&AttrIterator>,
136+
) -> Vec<Item> {
137+
let total_length = text.len() as i32;
138+
assert!(
139+
start_index >= 0 && start_index < total_length,
140+
"start_index is out of range"
141+
);
142+
assert!(
143+
length >= 0 && start_index.checked_add(length).unwrap() < total_length,
144+
"start_index + length is out of range"
145+
);
146+
unsafe {
147+
FromGlibPtrContainer::from_glib_full(ffi::pango_itemize_with_base_dir(
148+
context.to_glib_none().0,
149+
base_dir.into_glib(),
150+
text.to_glib_none().0,
151+
start_index,
152+
length,
153+
attrs.to_glib_none().0,
154+
mut_override(cached_iter.to_glib_none().0),
155+
))
156+
}
157+
}

0 commit comments

Comments
 (0)