-
Notifications
You must be signed in to change notification settings - Fork 208
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
Add nitf #294
Add nitf #294
Conversation
image/nitf.ksy
Outdated
ks-version: 0.9 | ||
encoding: UTF-8 | ||
endian: be | ||
license: CC-BY-SA-4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not usually used for software.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to MIT.
image/nitf.ksy
Outdated
type: encrypt | ||
- id: fbkgc | ||
size: 3 | ||
- id: oname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess names should be more meaningful. For original names there is -orig-id
. Could you also add doc
to each?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated these for many of the items. Full descriptions in the source doc linked are long and prose, so included some shortened ones where I felt the field could use more context.
image/nitf.ksy
Outdated
clasnfo: | ||
instances: | ||
total_size: | ||
value: (1 + 2 + 11 + 2 + 20 + 2 + 8 + 4 + 1 + 8 + 43 + 1 + 40 + 1 + 8 + 15) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sizeof<...>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@riverloopsec @rmspeers As @KOLANICH points out, there's really no need for such a lengthy and error-prone summation. Exactly this problem is addressed by the sizeof
operator (make sure you're using the latest unstable compiler version available from https://kaitai.io/#download, or you can use https://ide.kaitai.io/devel/, which has constantly the latest development version out of the box). But I noticed you already indicated ks-version: 0.9
in the top-level meta
section, so this shouldn't be a problem.
I saw that you're using it somewhere like reclasnfo.total_size
. You can replace this usage with either
- type-based sizeof:
sizeof<clasnfo>
- value-based sizeof:
reclasnfo._sizeof
Choose the one that suits you best. In both cases, you can delete this manually created attribute total_size
, the size of the whole clasnfo
type will be calculated automatically.
@KOLANICH can you look at this we ran into when updating? This is produced by KSV, no errors on KSC.
Note that I tried to switch ks-version to 0.8, which actually may be what broke this - rather than any changes to the format. Does that make sense? |
image/nitf.ksy
Outdated
seq: | ||
- id: des_base | ||
type: data_sub_header_base | ||
- id: desoflw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- should these 2 fields be separated in a struct?
- please don't merge words in variable names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
desoflw
is one from the original data, I'll go move these to orig-id and put instead other ids.
image/nitf.ksy
Outdated
type: tre_header | ||
band_info: | ||
seq: | ||
- id: n_band_representation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should n_band_
be ommitted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had it in there per the doc naming (pg 97 of reference), but have removed.
image/nitf.ksy
Outdated
- id: image_date_time | ||
-orig-id: idatim | ||
type: date_time | ||
doc: 'UTC time of image acquisition in the format CCYYMMDDhhmmss: CC century, YY last two digits of the year, MM month, DD day, hh hour, mm minute, ss second' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format of the time string docs should be moved into the struct representing time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved
FYI for a basic single image test see attached rgb16.ntf: |
image/nitf.ksy
Outdated
- id: image_data_mask | ||
type: image_data_mask | ||
if: has_mask | ||
- id: image_data_field | ||
size: _parent.header.linfo[idx].li.to_i - image_data_mask.total_size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing of the file rgb16.ntf
you provided in #294 (comment) fails due to image_data_mask
being null
(or more specifically, undefined
in JavaScript - tested on https://ide.kaitai.io/devel/), because you're unconditionally reading its total_size
attribute, whether it is null
or not. Shouldn't it have if: has_mask
as well?
@generalmimon / @KOLANICH - let me know if you see any other issues to resolve still. |
Apply suggestions from PR. Co-authored-by: Petr Pučil <[email protected]>
image/nitf.ksy
Outdated
- id: sctlh | ||
type: str | ||
size: 2 | ||
- id: srel | ||
type: str | ||
size: 20 | ||
- id: sdctp | ||
type: str | ||
size: 2 | ||
- id: sdcdt | ||
type: str | ||
size: 8 | ||
- id: sdcxm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that you improved a lot of field namings in 77c94a2, but I still feel that these (and similar ones) deserve a more meaningful id
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anything else we need to do or is this good to merge?
doc: | | ||
The NITF (National Image Transition Format) format is a file format developed by the U.S. Government for | ||
storing imagery, e.g. from satellites. | ||
|
||
According to the [foreword of the specification](https://gwg.nga.mil/ntb/baseline/docs/2500c/2500C.pdf): | ||
> The National Imagery Transmission Format Standard (NITFS) is the suite of standards for formatting digital | ||
> imagery and imagery-related products and exchanging them among members of the Intelligence Community (IC) as | ||
> defined by the Executive Order 12333, and other United States Government departments and agencies." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rmspeers A lot better! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me, you did a nice job! Just one small thing before we merge it (feel free to just apply the suggestion).
Co-authored-by: Petr Pučil <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@riverloopsec @rmspeers Thanks for your huge contribution, merging in!
This PR adds the NITF (National Image Transition Format) format specification.
Please see attached ZIP that has a selected set of NITF images collected from around the internet and carefully selected to have good coverage for testing purposes -
corpora.zip. In addition, https://github.com/codice/imaging-nitf/tree/master/shared-test-resources/src/main/resources is another repository of these files.
We have conducted extensive analysis of the security of this format using this as one of our methods for exploring it.
Credit to @TACIXAT for implementation.