Skip to content

Commit afb5f48

Browse files
committed
Merge branch 'check_input_charset'
2 parents 116bb7a + 03650dd commit afb5f48

File tree

8 files changed

+15
-34
lines changed

8 files changed

+15
-34
lines changed

.github/workflows/fuzz.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ roundtrip_confidential,
5151
echo "Using RUSTFLAGS $RUSTFLAGS"
5252
cd fuzz && ./fuzz.sh "${{ matrix.fuzz_target }}"
5353
- run: echo "${{ matrix.fuzz_target }}" >executed_${{ matrix.fuzz_target }}
54-
- uses: actions/upload-artifact@v2
54+
- uses: actions/upload-artifact@v4
5555
with:
5656
name: executed_${{ matrix.fuzz_target }}
5757
path: executed_${{ matrix.fuzz_target }}
@@ -62,7 +62,7 @@ roundtrip_confidential,
6262
runs-on: ubuntu-latest
6363
steps:
6464
- uses: actions/checkout@v2
65-
- uses: actions/download-artifact@v2
65+
- uses: actions/download-artifact@v4
6666
- name: Display structure of downloaded files
6767
run: ls -R
6868
- run: find executed_* -type f -exec cat {} + | sort > executed

fuzz/generate-files.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ $(for name in $(listTargetNames); do echo "$name,"; done)
8282
echo "Using RUSTFLAGS \$RUSTFLAGS"
8383
cd fuzz && ./fuzz.sh "\${{ matrix.fuzz_target }}"
8484
- run: echo "\${{ matrix.fuzz_target }}" >executed_\${{ matrix.fuzz_target }}
85-
- uses: actions/upload-artifact@v2
85+
- uses: actions/upload-artifact@v4
8686
with:
8787
name: executed_\${{ matrix.fuzz_target }}
8888
path: executed_\${{ matrix.fuzz_target }}

src/descriptor/checksum.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use core::fmt;
99
use core::iter::FromIterator;
1010

11+
use bitcoin_miniscript::expression::check_valid_chars;
12+
1113
use crate::Error;
1214

1315
const INPUT_CHARSET: &str = "0123456789()[],'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#\"\\ ";
@@ -51,11 +53,7 @@ pub fn desc_checksum(desc: &str) -> Result<String, Error> {
5153
/// if it is present and returns the descriptor string
5254
/// without the checksum
5355
pub(crate) fn verify_checksum(s: &str) -> Result<&str, Error> {
54-
for ch in s.as_bytes() {
55-
if *ch < 20 || *ch > 127 {
56-
return Err(Error::Unprintable(*ch));
57-
}
58-
}
56+
check_valid_chars(s)?;
5957

6058
let mut parts = s.splitn(2, '#');
6159
let desc_str = parts.next().unwrap();

src/descriptor/tr.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::str::FromStr;
44
use std::sync::{Arc, Mutex};
55
use std::{fmt, hash};
66

7+
use bitcoin_miniscript::expression::check_valid_chars;
78
use elements::taproot::{
89
LeafVersion, TaprootBuilder, TaprootSpendInfo, TAPROOT_CONTROL_BASE_SIZE,
910
TAPROOT_CONTROL_MAX_NODE_COUNT, TAPROOT_CONTROL_NODE_SIZE,
@@ -716,11 +717,7 @@ impl<Pk: MiniscriptKey, Ext: Extension> fmt::Display for Tr<Pk, Ext> {
716717

717718
// Helper function to parse string into miniscript tree form
718719
fn parse_tr_tree(s: &str) -> Result<expression::Tree<'_>, Error> {
719-
for ch in s.bytes() {
720-
if !ch.is_ascii() {
721-
return Err(Error::Unprintable(ch));
722-
}
723-
}
720+
check_valid_chars(s)?;
724721

725722
if s.len() > 5 && &s[..5] == "eltr(" && s.as_bytes()[s.len() - 1] == b')' {
726723
let rest = &s[5..s.len() - 1];

src/expression.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use std::fmt;
88
use std::str::FromStr;
99

10+
use bitcoin_miniscript::expression::check_valid_chars;
11+
1012
use crate::{errstr, Error, MAX_RECURSION_DEPTH};
1113

1214
#[derive(Debug, Clone)]
@@ -202,13 +204,7 @@ impl<'a> Tree<'a> {
202204
/// Parses a tree from a string
203205
#[allow(clippy::should_implement_trait)] // seems to be a false positive
204206
pub fn from_str(s: &'a str) -> Result<Tree<'a>, Error> {
205-
// Filter out non-ASCII because we byte-index strings all over the
206-
// place and Rust gets very upsbt when you splinch a string.
207-
for ch in s.bytes() {
208-
if !ch.is_ascii() {
209-
return Err(Error::Unprintable(ch));
210-
}
211-
}
207+
check_valid_chars(s)?;
212208

213209
let (top, rem) = Tree::from_slice(s)?;
214210
if rem.is_empty() {

src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ pub enum Error {
296296
CmsTooManyKeys(u32),
297297
/// A tapscript multi_a cannot support more than MAX_BLOCK_WEIGHT/32 keys
298298
MultiATooManyKeys(u32),
299-
/// Encountered unprintable character in descriptor
300-
Unprintable(u8),
301299
/// expected character while parsing descriptor; didn't find one
302300
ExpectedChar(char),
303301
/// While parsing backward, hit beginning of script
@@ -463,7 +461,6 @@ impl fmt::Display for Error {
463461
Error::Script(ref e) => fmt::Display::fmt(e, f),
464462
Error::AddrError(ref e) => fmt::Display::fmt(e, f),
465463
Error::CmsTooManyKeys(n) => write!(f, "checkmultisig with {} keys", n),
466-
Error::Unprintable(x) => write!(f, "unprintable character 0x{:02x}", x),
467464
Error::ExpectedChar(c) => write!(f, "expected {}", c),
468465
Error::UnexpectedStart => f.write_str("unexpected start of script"),
469466
Error::Unexpected(ref s) => write!(f, "unexpected «{}»", s),
@@ -537,7 +534,6 @@ impl error::Error for Error {
537534
| InvalidPush(_)
538535
| CmsTooManyKeys(_)
539536
| MultiATooManyKeys(_)
540-
| Unprintable(_)
541537
| ExpectedChar(_)
542538
| UnexpectedStart
543539
| Unexpected(_)

src/policy/concrete.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use std::collections::HashSet;
88
use std::{error, fmt, str};
99

10+
use bitcoin_miniscript::expression::check_valid_chars;
1011
use elements::{LockTime, Sequence};
1112
#[cfg(feature = "compiler")]
1213
use {
@@ -1098,11 +1099,7 @@ impl_from_str!(
10981099
Policy<Pk>,
10991100
type Err = Error;,
11001101
fn from_str(s: &str) -> Result<Policy<Pk>, Error> {
1101-
for ch in s.as_bytes() {
1102-
if *ch < 20 || *ch > 127 {
1103-
return Err(Error::Unprintable(*ch));
1104-
}
1105-
}
1102+
check_valid_chars(s)?;
11061103

11071104
let tree = expression::Tree::from_str(s)?;
11081105
let policy: Policy<Pk> = FromTree::from_tree(&tree)?;

src/policy/semantic.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use std::str::FromStr;
77
use std::{fmt, str};
88

9+
use bitcoin_miniscript::expression::check_valid_chars;
910
use elements::{LockTime, Sequence};
1011

1112
use super::concrete::PolicyError;
@@ -287,11 +288,7 @@ impl_from_str!(
287288
Policy<Pk>,
288289
type Err = Error;,
289290
fn from_str(s: &str) -> Result<Policy<Pk>, Error> {
290-
for ch in s.as_bytes() {
291-
if *ch < 20 || *ch > 127 {
292-
return Err(Error::Unprintable(*ch));
293-
}
294-
}
291+
check_valid_chars(s)?;
295292

296293
let tree = expression::Tree::from_str(s)?;
297294
expression::FromTree::from_tree(&tree)

0 commit comments

Comments
 (0)