Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ascii_i32 fallback only works on valid UTF-8 #11

Open
inferiorhumanorgans opened this issue Aug 31, 2023 · 3 comments
Open

ascii_i32 fallback only works on valid UTF-8 #11

inferiorhumanorgans opened this issue Aug 31, 2023 · 3 comments

Comments

@inferiorhumanorgans
Copy link

https://git.sr.ht/~az1/iso9660-rs/commit/47258d9499bce1b5cd7327e59367b66744f6a6a9.patch

From 47258d9499bce1b5cd7327e59367b66744f6a6a9 Mon Sep 17 00:00:00 2001
Date: Thu, 31 Aug 2023 13:18:10 -0700
Subject: [PATCH] ascii_i32: Treat zero-filled data as '0'.

This allows ascii_i32 to fall back on the default values for each date
component.  This allows iso9660 to parse this image:

https://archive.org/details/nokia-6210
---
 src/parse/date_time.rs | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/parse/date_time.rs b/src/parse/date_time.rs
index 7ff19f3..a9f0b45 100644
--- a/src/parse/date_time.rs
+++ b/src/parse/date_time.rs
@@ -1,7 +1,9 @@
 // SPDX-License-Identifier: (MIT OR Apache-2.0)
 
-use nom::bytes::complete::take;
-use nom::combinator::map_res;
+use nom::branch::alt;
+use nom::bytes::complete::{tag, take};
+use nom::combinator::{map_res, value};
+use nom::multi::count;
 use nom::number::complete::le_u8;
 use nom::sequence::tuple;
 use nom::IResult;
@@ -34,7 +36,12 @@ pub fn date_time(i: &[u8]) -> IResult<&[u8], OffsetDateTime> {
 }
 
 fn ascii_i32(n: usize) -> impl Fn(&[u8]) -> IResult<&[u8], i32> {
-    move |i: &[u8]| map_res(map_res(take(n), str::from_utf8), str::parse::<i32>)(i)
+    move |i: &[u8]| {
+        alt((
+            map_res(map_res(take(n), str::from_utf8), str::parse::<i32>),
+            value(0, count(tag(b"\0"), n)),
+        ))(i)
+    }
 }
 
 pub fn date_time_ascii(i: &[u8]) -> IResult<&[u8], OffsetDateTime> {
@ids1024
Copy link
Owner

ids1024 commented Sep 1, 2023

So this ISO has some kind of invalid bytes sequence in place of the date?

I wonder how other implementations handle this sort of thing.

@inferiorhumanorgans
Copy link
Author

Yes. There's a link to the image above. It mounts on OSX, I've not tested any other operating systems. It's worth noting though that UTF-8 non-digit characters would already fall through to the default date (when perhaps they ought not). This just accepts an empty field (all zeroes) as well.

@inferiorhumanorgans
Copy link
Author

Also, this is more or less the same issue as #8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants