ctb_formats_detection/decompression.rs
1/*
2$File: COPYING,v 1.2 2018/09/09 20:33:28 christos Exp $
3Copyright (c) Ian F. Darwin 1986, 1987, 1989, 1990, 1991, 1992, 1994, 1995.
4Software written by Ian F. Darwin and others;
5maintained 1994- Christos Zoulas.
6
7This software is not subject to any export provision of the United States
8Department of Commerce, and may be exported to any country or planet.
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions
12are met:
131. Redistributions of source code must retain the above copyright
14 notice immediately at the beginning of the file, without modification,
15 this list of conditions, and the following disclaimer.
162. Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in the
18 documentation and/or other materials provided with the distribution.
19
20THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30SUCH DAMAGE.
31
32The preceding notice is from COPYING in `file`.
33
34
35
36/*
37 * Copyright (c) Ian F. Darwin 1986-1995.
38 * Software written by Ian F. Darwin and others;
39 * maintained 1995-present by Christos Zoulas and others.
40 *
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
43 * are met:
44 * 1. Redistributions of source code must retain the above copyright
45 * notice immediately at the beginning of the file, without modification,
46 * this list of conditions, and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
55 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 */
63
64The preceding notice is from src/apprentice.c, src/ascmagic.c, src/compress.c, src/encoding.c, src/file.c, src/file.h, src/fsmagic.c, src/missing/asprintf.c, src/missing/dprintf.c, src/print.c, src/softmagic.c, src/swap.c, and src/swap.h in `file`.
65
66
67
68/*
69 * Copyright (c) Christos Zoulas 2017.
70 * All Rights Reserved.
71 *
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
74 * are met:
75 * 1. Redistributions of source code must retain the above copyright
76 * notice immediately at the beginning of the file, without modification,
77 * this list of conditions, and the following disclaimer.
78 * 2. Redistributions in binary form must reproduce the above copyright
79 * notice, this list of conditions and the following disclaimer in the
80 * documentation and/or other materials provided with the distribution.
81 *
82 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
83 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
84 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
85 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
86 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
87 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
88 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
89 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
90 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
91 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
92 * SUCH DAMAGE.
93 */
94
95The preceding notice is from src/buffer.c in `file`.
96
97
98
99/*
100 * Copyright (c) Christos Zoulas 2008.
101 * All Rights Reserved.
102 *
103 * Redistribution and use in source and binary forms, with or without
104 * modification, are permitted provided that the following conditions
105 * are met:
106 * 1. Redistributions of source code must retain the above copyright
107 * notice immediately at the beginning of the file, without modification,
108 * this list of conditions, and the following disclaimer.
109 * 2. Redistributions in binary form must reproduce the above copyright
110 * notice, this list of conditions and the following disclaimer in the
111 * documentation and/or other materials provided with the distribution.
112 *
113 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
114 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
115 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
116 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
117 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
118 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
119 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
120 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
121 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
122 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
123 * SUCH DAMAGE.
124 */
125
126The preceding notice is from src/elfclass.h in `file`.
127
128
129
130/*
131 * Copyright (c) Christos Zoulas 2003.
132 * All Rights Reserved.
133 *
134 * Redistribution and use in source and binary forms, with or without
135 * modification, are permitted provided that the following conditions
136 * are met:
137 * 1. Redistributions of source code must retain the above copyright
138 * notice immediately at the beginning of the file, without modification,
139 * this list of conditions, and the following disclaimer.
140 * 2. Redistributions in binary form must reproduce the above copyright
141 * notice, this list of conditions and the following disclaimer in the
142 * documentation and/or other materials provided with the distribution.
143 *
144 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
145 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
146 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
147 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
148 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
149 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
150 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
151 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
152 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
153 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
154 * SUCH DAMAGE.
155 */
156
157The preceding notice is from src/funcs.c, src/magic.c, src/magic.h.in, src/readelf.c, and src/readelf.h in `file`.
158
159
160
161/*
162 * Copyright (c) Ian F. Darwin 1986-1995.
163 * Software written by Ian F. Darwin and others;
164 * maintained 1995-present by Christos Zoulas and others.
165 *
166 * Redistribution and use in source and binary forms, with or without
167 * modification, are permitted provided that the following conditions
168 * are met:
169 * 1. Redistributions of source code must retain the above copyright
170 * notice immediately at the beginning of the file, without modification,
171 * this list of conditions, and the following disclaimer.
172 * 2. Redistributions in binary form must reproduce the above copyright
173 * notice, this list of conditions and the following disclaimer in the
174 * documentation and/or other materials provided with the distribution.
175 *
176 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
177 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
178 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
179 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
180 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
181 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
182 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
183 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
184 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
185 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
186 * SUCH DAMAGE.
187 */
188
189/*
190 * is_tar() -- figure out whether file is a tar archive.
191 *
192 * Stolen (by the author!) from the file_public domain tar program:
193 * Public Domain version written 26 Aug 1985 John Gilmore (ihnp4!hoptoad!gnu).
194 *
195 * @(#)list.c 1.18 9/23/86 Public Domain - gnu
196 *
197 * Comments changed and some code/comments reformatted
198 * for file command by Ian Darwin.
199 */
200
201The preceding notice is from src/is_tar.c in `file`.
202
203
204
205/*
206 * Redistribution and use in source and binary forms, with or without
207 * modification, are permitted provided that the following conditions
208 * are met:
209 * 1. Redistributions of source code must retain the above copyright
210 * notice immediately at the beginning of the file, without modification,
211 * this list of conditions, and the following disclaimer.
212 * 2. Redistributions in binary form must reproduce the above copyright
213 * notice, this list of conditions and the following disclaimer in the
214 * documentation and/or other materials provided with the distribution.
215 *
216 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
217 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
218 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
219 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
220 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
222 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
223 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
224 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
225 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
226 * SUCH DAMAGE.
227 */
228
229The preceding notice is from src/landlock.c and src/seccomp.c in `file`.
230
231
232
233/*
234 * Copyright (c) Christos Zoulas 2021.
235 * All Rights Reserved.
236 *
237 * Redistribution and use in source and binary forms, with or without
238 * modification, are permitted provided that the following conditions
239 * are met:
240 * 1. Redistributions of source code must retain the above copyright
241 * notice immediately at the beginning of the file, without modification,
242 * this list of conditions, and the following disclaimer.
243 * 2. Redistributions in binary form must reproduce the above copyright
244 * notice, this list of conditions and the following disclaimer in the
245 * documentation and/or other materials provided with the distribution.
246 *
247 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
248 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
249 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
250 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
251 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
252 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
253 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
254 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
255 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
256 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
257 * SUCH DAMAGE.
258 */
259
260The preceding notice is from src/memtest.c in `file`.
261
262
263
264/*
265 * Copyright (c) Ian F. Darwin 1986-1995.
266 * Software written by Ian F. Darwin and others;
267 * maintained 1995-present by Christos Zoulas and others.
268 *
269 * Redistribution and use in source and binary forms, with or without
270 * modification, are permitted provided that the following conditions
271 * are met:
272 * 1. Redistributions of source code must retain the above copyright
273 * notice immediately at the beginning of the file, without modification,
274 * this list of conditions, and the following disclaimer.
275 * 2. Redistributions in binary form must reproduce the above copyright
276 * notice, this list of conditions and the following disclaimer in the
277 * documentation and/or other materials provided with the distribution.
278 *
279 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
280 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
282 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
283 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
284 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
285 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
286 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
287 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
288 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
289 * SUCH DAMAGE.
290 */
291
292/*###########################################################################
293 # #
294 # vasprintf #
295 # #
296 # Copyright (c) 2002-2005 David TAILLANDIER #
297 # #
298 ###########################################################################*/
299
300/*
301
302This software is distributed under the "modified BSD licence".
303
304This software is also released with GNU license (GPL) in another file (same
305source-code, only license differ).
306
307
308
309Redistribution and use in source and binary forms, with or without
310modification, are permitted provided that the following conditions are met:
311
312Redistributions of source code must retain the above copyright notice, this
313list of conditions and the following disclaimer. Redistributions in binary
314form must reproduce the above copyright notice, this list of conditions and
315the following disclaimer in the documentation and/or other materials
316provided with the distribution. The name of the author may not be used to
317endorse or promote products derived from this software without specific
318prior written permission.
319
320THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
321WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
322MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
323EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
324SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
325PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
326OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
327WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
328OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
329ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
330
331====================
332
333Hacked from xnprintf version of 26th February 2005 to provide only
334vasprintf by Reuben Thomas <rrt@sc3d.org>.
335
336====================
337
338
339'printf' function family use the following format string:
340
341%[flag][width][.prec][modifier]type
342
343%% is the escape sequence to print a '%'
344% followed by an unknown format will print the characters without
345trying to do any interpretation
346
347flag: none + - # (blank)
348width: n 0n *
349prec: none .0 .n .*
350modifier: F N L h l ll z t ('F' and 'N' are ms-dos/16-bit specific)
351type: d i o u x X f e g E G c s p n
352
353
354The function needs to allocate memory to store the full text before to
355actually writing it. i.e if you want to fnprintf() 1000 characters, the
356functions will allocate 1000 bytes.
357This behaviour can be modified: you have to customise the code to flush the
358internal buffer (writing to screen or file) when it reach a given size. Then
359the buffer can have a shorter length. But what? If you really need to write
360HUGE string, don't use printf!
361During the process, some other memory is allocated (1024 bytes minimum)
362to handle the output of partial sprintf() calls. If you have only 10000 bytes
363free in memory, you *may* not be able to nprintf() an 8000 bytes-long text.
364
365note: if a buffer overflow occurs, exit() is called. This situation should
366never appear ... but if you want to be *really* sure, you have to modify the
367code to handle those situations (only one place to modify).
368A buffer overflow can only occur if your sprintf() do strange things or when
369you use strange formats.
370
371*/
372
373The preceding notice is from src/missing/vasprintf.c in `file`.
374
375
376
377/*
378 * Copyright (c) Ian F. Darwin 1986-1995.
379 * Software written by Ian F. Darwin and others;
380 * maintained 1995-present by Christos Zoulas and others.
381 *
382 * Redistribution and use in source and binary forms, with or without
383 * modification, are permitted provided that the following conditions
384 * are met:
385 * 1. Redistributions of source code must retain the above copyright
386 * notice immediately at the beginning of the file, without modification,
387 * this list of conditions, and the following disclaimer.
388 * 2. Redistributions in binary form must reproduce the above copyright
389 * notice, this list of conditions and the following disclaimer in the
390 * documentation and/or other materials provided with the distribution.
391 *
392 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
393 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
394 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
395 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
396 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
397 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
398 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
399 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
400 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
401 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
402 * SUCH DAMAGE.
403 */
404
405/*
406 * Header file for file_public domain tar (tape archive) program.
407 *
408 * @(#)tar.h 1.20 86/10/29 Public Domain.
409 *
410 * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
411 *
412 * $File: tar.h,v 1.16 2022/12/26 17:31:14 christos Exp $ # checkin only
413 */
414
415The preceding notice is from src/tar.h in `file`.
416*/
417
418// SPDX-License-Identifier: AGPL-3.0-or-later AND BSD-2-Clause-Darwin AND Apache-2.0 AND MIT AND BSD-3-Clause
419// SPDX-License-Identifier for parts derived from `file` (libmagic): BSD-2-Clause-Darwin AND BSD-3-Clause
420// SPDX-License-Identifier for parts derived from polyfile: Apache-2.0
421// SPDX-License-Identifier for parts derived from fileid and binwalk: MIT
422// SPDX-License-Identifier for parts derived from DROID: BSD-3-Clause
423/*
424This file is part of Collective Toolbox, a database and document workspace and utilities.
425Copyright (C) 2026 Collective Toolbox Developers
426Contact: info@collectivetoolbox.com
427
428This program is free software: you can redistribute it and/or modify it under
429the terms of the GNU Affero General Public License as published by the Free
430Software Foundation, either version 3 of the License, or (at your option) any
431later version.
432
433This program is distributed in the hope that it will be useful, but WITHOUT ANY
434WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
435A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
436
437You should have received a copy of the GNU Affero General Public License along
438with this program. If not, see <https://www.gnu.org/licenses/>.
439*/
440
441// The Collective Toolbox file detection tools, of which this file is a part, combine elements from several other similar tools: `file`, polyfile, binwalk, fileid, and DROID.
442// See license texts at the beginning and end of this file for full license details for parts derived from `file` <https://www.darwinsys.com/file/>.
443// See the full license details for parts derived from polyfile <https://github.com/trailofbits/polyfile>, binwalk <https://github.com/ReFirmLabs/binwalk>, fileid <https://github.com/DBHeise/fileid>, and DROID <https://github.com/digital-preservation/droid> at the end of this file.
444
445//! Transparent and deep recursive decompression inspection for format detection.
446//!
447//! Provides bounded stream decompression across all supported compression formats,
448//! enabling inspection of inner payloads, identification of compound formats (e.g. `TarGz`),
449//! format chains (`@chain(f... > f...)`), and UNIX `file` compatibility mode (`-z` / `-Z`).
450
451#[allow(
452 unused_imports,
453 clippy::wildcard_imports,
454 reason = "Standard workspace module prelude"
455)]
456use crate::utilities::*;
457
458use std::io::{self, Read, Write};
459
460use crate::extension::resolve_extension_candidates;
461use crate::mime_derivation::FORMAT_CATALOG;
462use crate::source::DetectionSource;
463use crate::types::{
464 ConfidenceTier, DetectionCandidate, DetectionEvidence, DetectionHint,
465 DetectionReport,
466};
467use ctb_formats_dcdata::format_spec::{
468 parse_format_expr, validate_format_expr,
469};
470
471/// Default byte limit (1 MiB) for bounded decompression probes during file inspection.
472pub const DEFAULT_DECOMPRESS_BYTE_LIMIT: usize = 1024 * 1024;
473
474/// Default maximum recursion depth allowed during recursive decompression inspection.
475pub const DEFAULT_MAX_DECOMPRESSION_DEPTH: usize = 3;
476
477/// Wraps a `DetectionSource` to implement `std::io::Read` by reading sequentially from offset 0.
478pub struct DetectionSourceReader<'a, S: DetectionSource + ?Sized> {
479 source: &'a mut S,
480 offset: u64,
481}
482
483impl<'a, S: DetectionSource + ?Sized> DetectionSourceReader<'a, S> {
484 /// Creates a new sequential reader starting at offset 0 of the given detection source.
485 pub fn new(source: &'a mut S) -> Self {
486 Self { source, offset: 0 }
487 }
488}
489
490impl<S: DetectionSource + ?Sized> Read for DetectionSourceReader<'_, S> {
491 fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
492 let n = self
493 .source
494 .read_at(self.offset, buf)
495 .map_err(|e| io::Error::other(e.to_string()))?;
496 let advance = u64::try_from(n).map_err(|e| {
497 io::Error::new(io::ErrorKind::InvalidData, e.to_string())
498 })?;
499 self.offset = self.offset.saturating_add(advance);
500 Ok(n)
501 }
502}
503
504/// A writer that collects up to `limit` bytes into an in-memory buffer,
505/// aborting with an error when the limit is exceeded to stop unbounded decompression.
506pub struct BoundedWriter {
507 buffer: Vec<u8>,
508 limit: usize,
509 limit_reached: bool,
510}
511
512impl BoundedWriter {
513 /// Creates a new `BoundedWriter` with the specified maximum byte capacity.
514 #[must_use]
515 pub fn new(limit: usize) -> Self {
516 Self {
517 buffer: Vec::new(),
518 limit,
519 limit_reached: false,
520 }
521 }
522
523 /// Returns whether the capacity limit was reached.
524 #[must_use]
525 pub fn is_limit_reached(&self) -> bool {
526 self.limit_reached
527 }
528
529 /// Consumes the writer and returns the collected decompressed bytes.
530 #[must_use]
531 pub fn into_inner(self) -> Vec<u8> {
532 self.buffer
533 }
534}
535
536impl Write for BoundedWriter {
537 fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
538 let remaining = self.limit.saturating_sub(self.buffer.len());
539 if remaining == 0 {
540 self.limit_reached = true;
541 return Err(io::Error::other("decompression byte limit reached"));
542 }
543 let take = buf.len().min(remaining);
544 if let Some(slice) = buf.get(..take) {
545 self.buffer.extend_from_slice(slice);
546 }
547 if self.buffer.len() >= self.limit {
548 self.limit_reached = true;
549 }
550 Ok(take)
551 }
552
553 fn flush(&mut self) -> io::Result<()> {
554 Ok(())
555 }
556}
557
558/// Decompresses up to `limit` bytes from `source` using the specified compression format.
559pub fn decompress_bounded<S: DetectionSource + ?Sized>(
560 source: &mut S,
561 format: FormatId,
562 limit: usize,
563) -> Result<Option<Vec<u8>>> {
564 let Ok(supported_format) = format.to_supported_decompression_format()
565 else {
566 return Ok(None);
567 };
568 let mut reader = DetectionSourceReader::new(source);
569 let mut writer = BoundedWriter::new(limit);
570 if let Err(error) = ctb_formats_compression::decompress_stream(
571 &mut reader,
572 &mut writer,
573 supported_format,
574 ) {
575 // A failed probe is a normal negative result during detection, but it
576 // must not vanish entirely: log at debug level for diagnosability.
577 debug_fmt!(
578 "Decompression probe for {format:?} produced no result: {error}"
579 );
580 }
581 let out = writer.into_inner();
582 if out.is_empty() {
583 return Ok(None);
584 }
585 Ok(Some(out))
586}
587
588/// Resolves an inner and outer format pair to a single compound `FormatId` if one is registered.
589#[must_use]
590pub fn resolve_compound_format(
591 inner: FormatId,
592 outer: FormatId,
593) -> Option<FormatId> {
594 if inner == FormatId::Tar {
595 match outer {
596 FormatId::Gzip => Some(FormatId::TarGz),
597 FormatId::CompressLzw
598 | FormatId::CompressLzw1
599 | FormatId::CompressLzw2
600 | FormatId::CompressLzw16 => Some(FormatId::TarZ),
601 FormatId::Bzip2 => Some(FormatId::TarBz2),
602 FormatId::Lzo => Some(FormatId::TarLzo),
603 _ => None,
604 }
605 } else {
606 None
607 }
608}
609
610/// Formats a canonical Document Character format chain directive
611/// `@chain(f_a > f_b > ...)` for layers ordered innermost → outermost.
612///
613/// Validates the emitted directive against the format expression grammar and AST validator.
614#[must_use]
615pub fn format_chain_directive(layers: &[FormatId]) -> String {
616 let shorthands: Vec<&str> =
617 layers.iter().map(FormatId::shorthand).collect();
618 let directive = format!("@chain({})", shorthands.join(" > "));
619 // A generated directive failing validation indicates a formatter bug;
620 // warn rather than emit an unparseable chain description silently.
621 match parse_format_expr(&directive).map(|expr| validate_format_expr(&expr))
622 {
623 Ok(Ok(())) => {}
624 Ok(Err(error)) => {
625 warn_fmt!(
626 "Format chain directive {directive} failed validation: {error}"
627 );
628 }
629 Err(error) => {
630 warn_fmt!(
631 "Format chain directive {directive} failed to parse: {error}"
632 );
633 }
634 }
635 directive
636}
637
638/// Resolves the display label for a format: catalog label, falling back to the
639/// format title or ident.
640#[must_use]
641fn format_chain_label(fid: FormatId) -> String {
642 // Reason for fallback: format without catalog entry uses format title or ident as label
643 FORMAT_CATALOG.lookup_format_id(fid).map_or_else(
644 || fid.title().unwrap_or(fid.ident()).to_string(),
645 |m| m.label.clone(),
646 )
647}
648
649/// Formats a human-readable pretty-printed format chain description,
650/// including format shorthands and full format titles/descriptions, for layers
651/// ordered innermost → outermost.
652#[must_use]
653pub fn format_chain_pretty(layers: &[FormatId]) -> String {
654 let directive = format_chain_directive(layers);
655 let labels: Vec<String> = layers
656 .iter()
657 .map(|fid| format!("\"{}\"", format_chain_label(*fid)))
658 .collect();
659 format!("{directive}: {}", labels.join(" > "))
660}
661
662/// Formats a single chain layer as `[fN Ident "label"]` for rich rendering.
663#[must_use]
664pub fn format_chain_layer_annotation(fid: FormatId) -> String {
665 format!(
666 "[{} {:?} \"{}\"]",
667 fid.shorthand(),
668 fid,
669 format_chain_label(fid)
670 )
671}
672
673/// Builds a `DetectionCandidate` representing a compound format (e.g. `TarGz`).
674#[must_use]
675pub fn build_compound_candidate(
676 compound_fid: FormatId,
677 inner_cand: &DetectionCandidate,
678 outer_cand: &DetectionCandidate,
679) -> DetectionCandidate {
680 let mapping = FORMAT_CATALOG.lookup_format_id(compound_fid);
681 // Reason for fallback: unmapped compound format defaults to inner and outer descriptions
682 let desc = mapping.map_or_else(
683 || format!("{} ({})", inner_cand.description, outer_cand.description),
684 |m| m.label.clone(),
685 );
686 let mime = mapping
687 .and_then(|m| m.mime_types.first().cloned())
688 .or_else(|| inner_cand.mime.clone());
689
690 DetectionCandidate {
691 format_id: Some(compound_fid),
692 dc_id: compound_fid.dc_id(),
693 mime,
694 description: desc,
695 confidence: ConfidenceTier::HighestConfidence,
696 score: 95,
697 evidence: vec![DetectionEvidence::ContainerStructure {
698 detail: format!(
699 "Decompressed payload identified as compound format {:?} [{}]",
700 compound_fid,
701 compound_fid.shorthand()
702 ),
703 score: 95,
704 }],
705 chain_layers: None,
706 }
707}
708
709/// Builds a `DetectionCandidate` representing an arbitrary format chain
710/// (`@chain(f_a > f_b > ...)`) with layers ordered innermost → outermost.
711#[must_use]
712pub fn build_format_chain_candidate(
713 inner_cand: &DetectionCandidate,
714 outer_cand: &DetectionCandidate,
715 layers: &[FormatId],
716) -> DetectionCandidate {
717 let pretty_desc = format_chain_pretty(layers);
718 // Reason for fallback: candidate without explicit MIME defaults to generic octet-stream
719 let inner_mime = inner_cand
720 .mime
721 .as_deref()
722 .unwrap_or("application/octet-stream");
723 // Reason for fallback: candidate without explicit MIME defaults to generic octet-stream
724 let outer_mime = outer_cand
725 .mime
726 .as_deref()
727 .unwrap_or("application/octet-stream");
728 let chain_mime = format!("{inner_mime} compressed-encoding={outer_mime}");
729
730 DetectionCandidate {
731 format_id: None,
732 dc_id: None,
733 mime: Some(chain_mime),
734 description: pretty_desc,
735 confidence: ConfidenceTier::Strong,
736 score: 94,
737 evidence: vec![DetectionEvidence::ContainerStructure {
738 detail: format!(
739 "Decompressed format chain {} validated",
740 format_chain_directive(layers)
741 ),
742 score: 94,
743 }],
744 chain_layers: Some(layers.to_vec()),
745 }
746}
747
748/// Builds a `DetectionCandidate` adhering to UNIX `file` compatibility mode conventions.
749#[must_use]
750pub fn build_compat_candidate(
751 inner_cand: &DetectionCandidate,
752 outer_cand: &DetectionCandidate,
753 uncompress_noreport: bool,
754) -> DetectionCandidate {
755 if uncompress_noreport {
756 // -Z mode: report inner description and MIME only
757 let mut cand = inner_cand.clone();
758 cand.score = cand.score.max(outer_cand.score);
759 cand.confidence = ConfidenceTier::HighestConfidence;
760 cand
761 } else {
762 // -z mode: report `<inner_desc> (<outer_desc>)`
763 let desc =
764 format!("{} ({})", inner_cand.description, outer_cand.description);
765 // Reason for fallback: candidate without explicit MIME defaults to generic octet-stream
766 let inner_mime = inner_cand
767 .mime
768 .as_deref()
769 .unwrap_or("application/octet-stream");
770 // Reason for fallback: candidate without explicit MIME defaults to generic octet-stream
771 let outer_mime = outer_cand
772 .mime
773 .as_deref()
774 .unwrap_or("application/octet-stream");
775 let mime = format!("{inner_mime} compressed-encoding={outer_mime}");
776
777 DetectionCandidate {
778 format_id: inner_cand.format_id,
779 dc_id: inner_cand.dc_id,
780 mime: Some(mime),
781 description: desc,
782 confidence: ConfidenceTier::HighestConfidence,
783 score: outer_cand.score.max(inner_cand.score),
784 evidence: inner_cand.evidence.clone(),
785 chain_layers: inner_cand.chain_layers.clone(),
786 }
787 }
788}
789
790/// Probes a compressed source, decompressing up to the configured limit and recursively
791/// identifying the inner payload format.
792pub fn probe_decompression_candidates<S: DetectionSource + ?Sized, FReport>(
793 source: &mut S,
794 outer_candidates: &[DetectionCandidate],
795 hint: Option<&DetectionHint>,
796 mut run_inner_report: FReport,
797) -> Result<Vec<DetectionCandidate>>
798where
799 FReport: FnMut(
800 &mut dyn DetectionSource,
801 Option<&DetectionHint>,
802 ) -> Result<DetectionReport>,
803{
804 // Reason for fallback: hint defaults to non-compat mode if omitted
805 let compat = hint.is_some_and(|h| h.compat);
806 // Reason for fallback: hint defaults to false for uncompress if omitted
807 let uncompress = hint.is_some_and(|h| h.uncompress);
808 // Reason for fallback: hint defaults to false for uncompress_noreport if omitted
809 let uncompress_noreport = hint.is_some_and(|h| h.uncompress_noreport);
810 // Reason for fallback: initial decompression depth defaults to 0 if omitted
811 let depth = hint.map_or(0, |h| h.recursion_depth);
812 // Reason for fallback: hint defaults to the documented default depth limit if omitted
813 let max_depth = hint
814 .and_then(|h| h.max_decompression_depth)
815 .unwrap_or(DEFAULT_MAX_DECOMPRESSION_DEPTH);
816
817 // In compat mode, do NOT decompress unless -z or -Z is passed
818 if compat && !uncompress && !uncompress_noreport {
819 return Ok(Vec::new());
820 }
821
822 // A limit of 0 disables decompression probing entirely.
823 if depth >= max_depth {
824 return Ok(Vec::new());
825 }
826
827 // Locate the candidate outer compression format
828 // Reason for fallback: candidate lacking format_id cannot be a recognized compression algorithm
829 let outer_cand = outer_candidates.iter().find(|c| {
830 c.format_id
831 .is_some_and(ctb_formats_compression::is_supported)
832 });
833
834 let synth_outer: DetectionCandidate;
835 let (outer_fid, outer_candidate_ref) = if let Some(cand) = outer_cand {
836 let Some(fid) = cand.format_id else {
837 return Ok(Vec::new());
838 };
839 (fid, cand)
840 } else {
841 // No magic-detected compression format: fall back to the filename
842 // extension so extension-named compressed payloads still get
843 // decompressed and inspected.
844 let ext_fmt = hint
845 .and_then(|h| h.extension.as_deref().or(h.filename.as_deref()))
846 .map(|name| {
847 let clean = name.trim().trim_start_matches('.');
848 // Reason for fallback: filename without period delimiter is already the extension
849 let last_ext = clean.rsplit('.').next().unwrap_or(clean);
850 resolve_extension_candidates(last_ext, None)
851 })
852 .into_iter()
853 .flatten()
854 .map(|(fid, _)| fid)
855 .find(|fid| ctb_formats_compression::is_supported(*fid));
856
857 let Some(fid) = ext_fmt else {
858 return Ok(Vec::new());
859 };
860
861 // Reason for fallback: unmapped format uses debug format name
862 let desc = FORMAT_CATALOG.lookup_format_id(fid).map_or_else(
863 || format!("{fid:?} compressed data"),
864 |m| m.label.clone(),
865 );
866 let mime = FORMAT_CATALOG
867 .lookup_format_id(fid)
868 .and_then(|m| m.mime_types.first().cloned());
869 synth_outer = DetectionCandidate {
870 format_id: Some(fid),
871 dc_id: fid.dc_id(),
872 mime,
873 description: desc,
874 confidence: ConfidenceTier::Moderate,
875 score: 80,
876 evidence: Vec::new(),
877 chain_layers: None,
878 };
879 (fid, &synth_outer)
880 };
881
882 // Reason for fallback: default bounded inspection limit if unspecified in hint
883 let limit = hint
884 .and_then(|h| h.decompress_byte_limit)
885 .unwrap_or(DEFAULT_DECOMPRESS_BYTE_LIMIT);
886
887 let Some(decompressed) = decompress_bounded(source, outer_fid, limit)?
888 else {
889 return Ok(Vec::new());
890 };
891
892 if decompressed.is_empty() {
893 return Ok(Vec::new());
894 }
895
896 // Prepare inner detection hint
897 // Reason for fallback: detection hint defaults to empty if not supplied
898 let mut inner_hint = hint.cloned().unwrap_or_default();
899 inner_hint.recursion_depth = depth.saturating_add(1);
900 inner_hint.uncompress = false;
901 inner_hint.uncompress_noreport = false;
902
903 // Strip outer compression extension from filename if present
904 if let Some(filename) = &inner_hint.filename {
905 let stripped = if let Some((stem, _)) = filename.rsplit_once('.') {
906 stem.to_string()
907 } else {
908 filename.clone()
909 };
910 inner_hint.extension =
911 stripped.rsplit_once('.').map(|(_, ext)| ext.to_string());
912 inner_hint.filename = Some(stripped);
913 }
914
915 let mut inner_source = decompressed.as_slice();
916 let inner_report = run_inner_report(&mut inner_source, Some(&inner_hint))?;
917
918 let inner_cand = inner_report.candidates.first();
919
920 let mut results = Vec::new();
921
922 if compat {
923 let mut outer_for_compat = outer_candidate_ref.clone();
924 if let Some(magic_desc) =
925 outer_candidate_ref.evidence.iter().find_map(|e| match e {
926 DetectionEvidence::FileMagic { description, .. } => {
927 Some(description.clone())
928 }
929 _ => None,
930 })
931 {
932 outer_for_compat.description = magic_desc;
933 }
934
935 if let Some(inner) = inner_cand {
936 results.push(build_compat_candidate(
937 inner,
938 &outer_for_compat,
939 uncompress_noreport,
940 ));
941 } else {
942 let synth_inner = DetectionCandidate {
943 format_id: None,
944 dc_id: None,
945 mime: Some("application/octet-stream".to_string()),
946 description: "data".to_string(),
947 confidence: ConfidenceTier::Weak,
948 score: 20,
949 evidence: Vec::new(),
950 chain_layers: None,
951 };
952 results.push(build_compat_candidate(
953 &synth_inner,
954 &outer_for_compat,
955 uncompress_noreport,
956 ));
957 }
958 } else {
959 // Default rich mode: generate compound candidate and format chain candidate
960 if let Some(inner) = inner_cand {
961 if let Some(inner_fid) = inner.format_id {
962 if let Some(compound_fid) =
963 resolve_compound_format(inner_fid, outer_fid)
964 {
965 results.push(build_compound_candidate(
966 compound_fid,
967 inner,
968 outer_candidate_ref,
969 ));
970 }
971 results.push(build_format_chain_candidate(
972 inner,
973 outer_candidate_ref,
974 &[inner_fid, outer_fid],
975 ));
976 } else if let Some(mut layers) = inner.chain_layers.clone() {
977 // Inner candidate is itself a decompression chain: merge into a
978 // deeper chain by appending the outer layer (innermost → outermost).
979 layers.push(outer_fid);
980 results.push(build_format_chain_candidate(
981 inner,
982 outer_candidate_ref,
983 &layers,
984 ));
985 } else {
986 // Inner candidate has no registered FormatId (e.g. arbitrary text / data)
987 let desc = format!(
988 "{} ({})",
989 inner.description, outer_candidate_ref.description
990 );
991 // Reason for fallback: candidate without explicit MIME defaults to generic octet-stream
992 let inner_mime =
993 inner.mime.as_deref().unwrap_or("application/octet-stream");
994 // Reason for fallback: candidate without explicit MIME defaults to generic octet-stream
995 let outer_mime = outer_candidate_ref
996 .mime
997 .as_deref()
998 .unwrap_or("application/octet-stream");
999 let chain_mime =
1000 format!("{inner_mime} compressed-encoding={outer_mime}");
1001 results.push(DetectionCandidate {
1002 format_id: None,
1003 dc_id: None,
1004 mime: Some(chain_mime),
1005 description: desc,
1006 confidence: ConfidenceTier::Strong,
1007 score: 94,
1008 evidence: vec![DetectionEvidence::ContainerStructure {
1009 detail: format!(
1010 "Decompressed payload identified as {} inside {:?}",
1011 inner.description, outer_fid
1012 ),
1013 score: 94,
1014 }],
1015 chain_layers: None,
1016 });
1017 }
1018 }
1019 }
1020
1021 Ok(results)
1022}
1023
1024#[cfg(test)]
1025#[allow(
1026 clippy::panic,
1027 clippy::expect_used,
1028 clippy::unwrap_used,
1029 clippy::unwrap_in_result,
1030 clippy::panic_in_result_fn,
1031 clippy::indexing_slicing,
1032 clippy::arithmetic_side_effects,
1033 reason = "Standard repository test boilerplate"
1034)]
1035mod tests {
1036 use super::*;
1037 use crate::detection::guess_format_report;
1038
1039 /// Builds a synthetic `CscJournal4` payload for decompression chain tests.
1040 fn csc_journal_v4_bytes() -> Vec<u8> {
1041 let mut data = Vec::new();
1042 data.extend_from_slice(b"CTBCSCJ\x04");
1043 data.extend_from_slice(
1044 b"\x00\x01\x02\x03 synthetic journal payload for detection",
1045 );
1046 data
1047 }
1048
1049 fn make_test_tar_bytes() -> Vec<u8> {
1050 let mut tar_bytes = vec![0u8; 512];
1051 tar_bytes[..9].copy_from_slice(b"test.txt\0");
1052 tar_bytes[100..108].copy_from_slice(b"0000644\0");
1053 tar_bytes[108..116].copy_from_slice(b"0001750\0");
1054 tar_bytes[116..124].copy_from_slice(b"0001750\0");
1055 tar_bytes[124..136].copy_from_slice(b"00000000000\0");
1056 tar_bytes[136..148].copy_from_slice(b"14713210000\0");
1057 tar_bytes[156] = b'0';
1058 tar_bytes[257..265].copy_from_slice(b"ustar\000");
1059
1060 let mut sum: u32 = 0;
1061 for (i, &b) in tar_bytes.iter().enumerate() {
1062 if (148..156).contains(&i) {
1063 sum = sum.saturating_add(u32::from(b' '));
1064 } else {
1065 sum = sum.saturating_add(u32::from(b));
1066 }
1067 }
1068 let chksum_str = format!("{sum:06o}\0 ");
1069 tar_bytes[148..156].copy_from_slice(chksum_str.as_bytes());
1070 tar_bytes
1071 }
1072
1073 #[ctb_test]
1074 fn test_bounded_writer_limits() {
1075 let mut writer = BoundedWriter::new(10);
1076 assert_eq!(writer.write(b"12345").unwrap(), 5);
1077 assert!(!writer.is_limit_reached());
1078 assert_eq!(writer.write(b"67890123").unwrap(), 5);
1079 assert!(writer.is_limit_reached());
1080 writer.write(b"more").unwrap_err();
1081 assert_eq!(writer.into_inner(), b"1234567890");
1082 }
1083
1084 #[ctb_test]
1085 fn test_compound_format_resolution() {
1086 assert_eq!(
1087 resolve_compound_format(FormatId::Tar, FormatId::Gzip),
1088 Some(FormatId::TarGz)
1089 );
1090 assert_eq!(
1091 resolve_compound_format(FormatId::Tar, FormatId::CompressLzw),
1092 Some(FormatId::TarZ)
1093 );
1094 assert_eq!(
1095 resolve_compound_format(FormatId::Tar, FormatId::CompressLzw16),
1096 Some(FormatId::TarZ)
1097 );
1098 assert_eq!(
1099 resolve_compound_format(FormatId::Tar, FormatId::Bzip2),
1100 Some(FormatId::TarBz2)
1101 );
1102 assert_eq!(
1103 resolve_compound_format(FormatId::Tar, FormatId::Lzo),
1104 Some(FormatId::TarLzo)
1105 );
1106 assert_eq!(
1107 resolve_compound_format(FormatId::Json, FormatId::Zstd),
1108 None
1109 );
1110 }
1111
1112 #[ctb_test]
1113 fn test_format_chain_directive_and_pretty() {
1114 let directive =
1115 format_chain_directive(&[FormatId::Tar, FormatId::CompressLzw]);
1116 assert_eq!(directive, "@chain(f161 > f44)");
1117
1118 let expr = parse_format_expr(&directive)
1119 .expect("Should parse chain directive");
1120 validate_format_expr(&expr).expect("Should validate chain expression");
1121
1122 let pretty =
1123 format_chain_pretty(&[FormatId::Tar, FormatId::CompressLzw]);
1124 assert!(pretty.starts_with("@chain(f161 > f44):"));
1125 assert!(pretty.contains("tar"));
1126
1127 // A flat 3-layer chain is valid DSL: operational operators bind
1128 // left-to-right, so `a > b > c` parses as `(a > b) > c`.
1129 let nested = format_chain_directive(&[
1130 FormatId::CscJournal4,
1131 FormatId::Gzip,
1132 FormatId::Gzip,
1133 ]);
1134 assert_eq!(nested, "@chain(f632 > f35 > f35)");
1135 let nested_expr = parse_format_expr(&nested)
1136 .expect("Flat 3-layer chain should parse");
1137 validate_format_expr(&nested_expr)
1138 .expect("Flat 3-layer chain should validate");
1139 }
1140
1141 #[ctb_test]
1142 fn test_decompression_probe_targz_compat_and_rich() {
1143 let tar_data = make_test_tar_bytes();
1144 let gz_bytes = ctb_formats_compression::compress(
1145 &tar_data,
1146 SupportedCompressionFormat::Gzip,
1147 )
1148 .expect("Compression should succeed");
1149
1150 // 1. Compat mode without -z / -Z: no decompression
1151 let compat_hint = DetectionHint {
1152 compat: true,
1153 ..Default::default()
1154 };
1155 let rep1 =
1156 guess_format_report(&mut gz_bytes.as_slice(), Some(&compat_hint))
1157 .unwrap();
1158 assert_eq!(rep1.candidates[0].format_id, Some(FormatId::Gzip));
1159 assert!(
1160 rep1.candidates[0]
1161 .description
1162 .to_ascii_lowercase()
1163 .contains("gzip")
1164 );
1165
1166 // 2. Compat mode with -z: reports `<inner> (<outer>)`
1167 let z_hint = DetectionHint {
1168 compat: true,
1169 uncompress: true,
1170 ..Default::default()
1171 };
1172 let rep2 = guess_format_report(&mut gz_bytes.as_slice(), Some(&z_hint))
1173 .unwrap();
1174 assert!(
1175 rep2.candidates[0]
1176 .description
1177 .to_ascii_lowercase()
1178 .contains("tar archive")
1179 );
1180 assert!(
1181 rep2.candidates[0]
1182 .description
1183 .to_ascii_lowercase()
1184 .contains("(gzip")
1185 );
1186 assert!(
1187 rep2.candidates[0]
1188 .mime
1189 .as_deref()
1190 .unwrap()
1191 .contains("compressed-encoding=")
1192 );
1193
1194 // 3. Compat mode with -Z: reports `<inner>` only
1195 let cap_z_hint = DetectionHint {
1196 compat: true,
1197 uncompress_noreport: true,
1198 ..Default::default()
1199 };
1200 let rep3 =
1201 guess_format_report(&mut gz_bytes.as_slice(), Some(&cap_z_hint))
1202 .unwrap();
1203 assert!(
1204 rep3.candidates[0]
1205 .description
1206 .to_ascii_lowercase()
1207 .contains("tar archive")
1208 );
1209 assert!(
1210 !rep3.candidates[0]
1211 .description
1212 .to_ascii_lowercase()
1213 .contains("(gzip")
1214 );
1215
1216 // 4. Default rich mode: compound format TarGz is top, followed by format chain
1217 let rep4 = guess_format_report(&mut gz_bytes.as_slice(), None).unwrap();
1218 assert_eq!(rep4.candidates[0].format_id, Some(FormatId::TarGz));
1219 assert!(
1220 rep4.candidates
1221 .iter()
1222 .any(|c| c.description.contains("@chain(f161 > f35)"))
1223 );
1224 }
1225
1226 #[ctb_test]
1227 fn test_decompression_probe_tar_bzip2() {
1228 let tar_data = make_test_tar_bytes();
1229 let bz2_bytes = ctb_formats_compression::compress(
1230 &tar_data,
1231 SupportedCompressionFormat::Bzip2,
1232 )
1233 .expect("Compression should succeed");
1234
1235 // Default rich mode: TarBz2 is top, format chain is present
1236 let rep = guess_format_report(&mut bz2_bytes.as_slice(), None).unwrap();
1237 assert_eq!(rep.candidates[0].format_id, Some(FormatId::TarBz2));
1238 assert!(
1239 rep.candidates
1240 .iter()
1241 .any(|c| c.description.contains("@chain(f161 > f38)"))
1242 );
1243
1244 // Compat -z mode
1245 let z_hint = DetectionHint {
1246 compat: true,
1247 uncompress: true,
1248 ..Default::default()
1249 };
1250 let rep_z =
1251 guess_format_report(&mut bz2_bytes.as_slice(), Some(&z_hint))
1252 .unwrap();
1253 assert!(
1254 rep_z.candidates[0]
1255 .description
1256 .to_ascii_lowercase()
1257 .contains("tar archive")
1258 );
1259 assert!(
1260 rep_z.candidates[0]
1261 .description
1262 .to_ascii_lowercase()
1263 .contains("(bzip2")
1264 );
1265 }
1266
1267 #[ctb_test]
1268 fn test_decompression_probe_json_zstd() {
1269 let json_data = br#"{"name":"ctoolbox","version":1}"#;
1270 let zst_bytes = ctb_formats_compression::compress(
1271 json_data,
1272 SupportedCompressionFormat::Zstd,
1273 )
1274 .expect("Zstd compression should succeed");
1275
1276 // Default rich mode: non-compound pair emits @chain(f... > f...)
1277 let rep = guess_format_report(&mut zst_bytes.as_slice(), None).unwrap();
1278 let top = &rep.candidates[0];
1279 assert!(top.description.contains("@chain("));
1280 assert!(top.description.contains("> f40)")); // Zstd is f40
1281 assert!(top.description.contains("JSON"));
1282
1283 // Compat -z mode
1284 let z_hint = DetectionHint {
1285 compat: true,
1286 uncompress: true,
1287 ..Default::default()
1288 };
1289 let rep_z =
1290 guess_format_report(&mut zst_bytes.as_slice(), Some(&z_hint))
1291 .unwrap();
1292 assert!(rep_z.candidates[0].description.contains("JSON"));
1293 assert!(
1294 rep_z.candidates[0]
1295 .description
1296 .to_ascii_lowercase()
1297 .contains("(zstandard")
1298 );
1299 }
1300
1301 #[ctb_test]
1302 fn test_decompression_probe_shell_script_gzip() {
1303 let script_data = b"#!/bin/sh\necho 'hello world'\n";
1304 let gz_bytes = ctb_formats_compression::compress(
1305 script_data,
1306 SupportedCompressionFormat::Gzip,
1307 )
1308 .expect("Gzip compression should succeed");
1309
1310 // Default rich mode: non-compound pair emits @chain
1311 let rep = guess_format_report(&mut gz_bytes.as_slice(), None).unwrap();
1312 let top = &rep.candidates[0];
1313 assert!(top.description.contains("@chain("));
1314 assert!(top.description.contains("> f35)")); // Gzip is f35
1315
1316 // Compat -z mode
1317 let z_hint = DetectionHint {
1318 compat: true,
1319 uncompress: true,
1320 ..Default::default()
1321 };
1322 let rep_z =
1323 guess_format_report(&mut gz_bytes.as_slice(), Some(&z_hint))
1324 .unwrap();
1325 assert!(rep_z.candidates[0].description.contains("script"));
1326 assert!(
1327 rep_z.candidates[0]
1328 .description
1329 .to_ascii_lowercase()
1330 .contains("(gzip")
1331 );
1332 }
1333
1334 #[ctb_test]
1335 fn test_nested_gzip_chain_merges_layers() {
1336 let inner = ctb_formats_compression::compress(
1337 &csc_journal_v4_bytes(),
1338 SupportedCompressionFormat::Gzip,
1339 )
1340 .expect("Inner compression should succeed");
1341 let compressed = ctb_formats_compression::compress(
1342 &inner,
1343 SupportedCompressionFormat::Gzip,
1344 )
1345 .expect("Outer compression should succeed");
1346 let mut slice: &[u8] = &compressed;
1347 let hint = DetectionHint {
1348 filename: Some("x.cscjournal.gz.gz".to_string()),
1349 ..Default::default()
1350 };
1351 let report = guess_format_report(&mut slice, Some(&hint)).unwrap();
1352 let top = &report.candidates[0];
1353 assert!(
1354 top.format_id.is_none(),
1355 "Chain candidate should keep format_id unassigned"
1356 );
1357 let layers = top
1358 .chain_layers
1359 .as_ref()
1360 .expect("Top candidate should carry merged chain layers");
1361 assert_eq!(layers.len(), 3);
1362 assert_eq!(layers[0], FormatId::CscJournal4);
1363 assert_eq!(layers[1], FormatId::Gzip);
1364 assert_eq!(layers[2], FormatId::Gzip);
1365 assert!(
1366 top.description.starts_with("@chain(f632 > f35 > f35):"),
1367 "Expected 3-layer chain directive, got: {}",
1368 top.description
1369 );
1370 }
1371
1372 #[ctb_test]
1373 fn test_zero_max_decompression_depth_disables_probing() {
1374 let compressed = ctb_formats_compression::compress(
1375 &csc_journal_v4_bytes(),
1376 SupportedCompressionFormat::Gzip,
1377 )
1378 .expect("Compression should succeed");
1379 let hint = DetectionHint {
1380 filename: Some("journal.cscjournal.gz".to_string()),
1381 max_decompression_depth: Some(0),
1382 ..Default::default()
1383 };
1384
1385 // Direct report path
1386 let mut slice: &[u8] = &compressed;
1387 let report = guess_format_report(&mut slice, Some(&hint)).unwrap();
1388 assert!(
1389 !report.candidates.iter().any(|c| c.chain_layers.is_some()),
1390 "No chain candidates should be produced at depth limit 0"
1391 );
1392 assert_eq!(report.candidates[0].format_id, Some(FormatId::Gzip));
1393
1394 // File-report path, which must propagate the depth limit from the
1395 // caller-supplied hint into the internally built hint.
1396 let vec_report = crate::detection::guess_and_report_vec_with_hint(
1397 compressed,
1398 Some(&hint),
1399 )
1400 .unwrap();
1401 assert!(
1402 !vec_report
1403 .candidates
1404 .iter()
1405 .any(|c| c.chain_layers.is_some()),
1406 "No chain candidates should be produced at depth limit 0"
1407 );
1408 }
1409
1410 #[ctb_test]
1411 fn test_extension_fallback_decompresses_without_magic() {
1412 // Raw DEFLATE has no magic signature: the outer format is only known
1413 // from the filename, exercising the extension-fallback probe path.
1414 let payload = "hello world\n".repeat(40).into_bytes();
1415 let deflated = ctb_formats_compression::compress(
1416 &payload,
1417 SupportedCompressionFormat::Deflate,
1418 )
1419 .expect("Deflate compression should succeed");
1420 let mut slice: &[u8] = &deflated;
1421 let hint = DetectionHint {
1422 filename: Some("payload.deflate".to_string()),
1423 ..Default::default()
1424 };
1425 let report = guess_format_report(&mut slice, Some(&hint)).unwrap();
1426 let top = &report.candidates[0];
1427 let layers = top.chain_layers.as_ref().expect(
1428 "Extension-only outer should still produce a chain candidate",
1429 );
1430 assert_eq!(
1431 layers.first(),
1432 Some(&FormatId::Ascii),
1433 "Inner ASCII text should be the innermost layer"
1434 );
1435 assert_eq!(layers.last(), Some(&FormatId::Deflate));
1436 assert!(top.description.starts_with("@chain(f4 > "));
1437 }
1438
1439 #[ctb_test]
1440 fn test_extension_fallback_garbage_yields_no_chain() {
1441 // A file that merely carries a compressed-extension name must fail
1442 // the decompression probe cleanly without erroring detection.
1443 let garbage = "not gzip data at all, just plain text\n"
1444 .repeat(4)
1445 .into_bytes();
1446 let mut slice: &[u8] = &garbage;
1447 let hint = DetectionHint {
1448 filename: Some("garbage.gz".to_string()),
1449 ..Default::default()
1450 };
1451 let report = guess_format_report(&mut slice, Some(&hint)).unwrap();
1452 assert!(
1453 report.candidates.iter().all(|c| c.chain_layers.is_none()),
1454 "Garbage with a compressed extension must not yield chain candidates"
1455 );
1456 }
1457}
1458/*
1459/*
1460 * Adapted from: apptype.c, Written by Eberhard Mattes and put into the
1461 * file_public domain
1462 *
1463 * Notes: 1. Qualify the filename so that DosQueryAppType does not do extraneous
1464 * searches.
1465 *
1466 * 2. DosQueryAppType will return FAPPTYP_DOS on a file ending with ".com"
1467 * (other than an OS/2 exe or Win exe with this name). Eberhard Mattes
1468 * remarks Tue, 6 Apr 93: Moreover, it reports the type of the (new and very
1469 * bug ridden) Win Emacs as "OS/2 executable".
1470 *
1471 * 3. apptype() uses the filename if given, otherwise a tmp file is created with
1472 * the contents of buf. If buf is not the complete file, apptype can
1473 * incorrectly identify the exe type. The "-z" option of "file" is the reason
1474 * for this ugly code.
1475 */
1476
1477The preceding notice is from src/apptype.c in `file`.
1478
1479
1480
1481/*-
1482 * Copyright (c) 2008 Christos Zoulas
1483 * All rights reserved.
1484 *
1485 * Redistribution and use in source and binary forms, with or without
1486 * modification, are permitted provided that the following conditions
1487 * are met:
1488 * 1. Redistributions of source code must retain the above copyright
1489 * notice, this list of conditions and the following disclaimer.
1490 * 2. Redistributions in binary form must reproduce the above copyright
1491 * notice, this list of conditions and the following disclaimer in the
1492 * documentation and/or other materials provided with the distribution.
1493 *
1494 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1495 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1496 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1497 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1498 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1499 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1500 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1501 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1502 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1503 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1504 * POSSIBILITY OF SUCH DAMAGE.
1505 */
1506
1507The preceding notice is from src/cdf.c, src/cdf.h, and src/cdf_time.c in `file`.
1508
1509
1510
1511/*-
1512 * Copyright (c) 2016 Christos Zoulas
1513 * All rights reserved.
1514 *
1515 * Redistribution and use in source and binary forms, with or without
1516 * modification, are permitted provided that the following conditions
1517 * are met:
1518 * 1. Redistributions of source code must retain the above copyright
1519 * notice, this list of conditions and the following disclaimer.
1520 * 2. Redistributions in binary form must reproduce the above copyright
1521 * notice, this list of conditions and the following disclaimer in the
1522 * documentation and/or other materials provided with the distribution.
1523 *
1524 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1525 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1526 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1527 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1528 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1529 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1530 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1531 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1532 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1533 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1534 * POSSIBILITY OF SUCH DAMAGE.
1535 */
1536
1537The preceding notice is from src/der.c and src/der.h in `file`.
1538
1539
1540
1541/*-
1542 * Copyright (c) 2019 Christos Zoulas
1543 * All rights reserved.
1544 *
1545 * Redistribution and use in source and binary forms, with or without
1546 * modification, are permitted provided that the following conditions
1547 * are met:
1548 * 1. Redistributions of source code must retain the above copyright
1549 * notice, this list of conditions and the following disclaimer.
1550 * 2. Redistributions in binary form must reproduce the above copyright
1551 * notice, this list of conditions and the following disclaimer in the
1552 * documentation and/or other materials provided with the distribution.
1553 *
1554 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1555 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1556 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1557 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1558 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1559 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1560 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1561 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1562 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1563 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1564 * POSSIBILITY OF SUCH DAMAGE.
1565 */
1566
1567The preceding notice is from src/is_csv.c in `file`.
1568
1569
1570
1571/*-
1572 * Copyright (c) 2018 Christos Zoulas
1573 * All rights reserved.
1574 *
1575 * Redistribution and use in source and binary forms, with or without
1576 * modification, are permitted provided that the following conditions
1577 * are met:
1578 * 1. Redistributions of source code must retain the above copyright
1579 * notice, this list of conditions and the following disclaimer.
1580 * 2. Redistributions in binary form must reproduce the above copyright
1581 * notice, this list of conditions and the following disclaimer in the
1582 * documentation and/or other materials provided with the distribution.
1583 *
1584 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1585 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1586 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1587 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1588 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1589 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1590 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1591 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1592 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1593 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1594 * POSSIBILITY OF SUCH DAMAGE.
1595 */
1596
1597The preceding notice is from src/is_json.c in `file`.
1598
1599
1600
1601/*-
1602 * Copyright (c) 2023 Christos Zoulas
1603 * All rights reserved.
1604 *
1605 * Redistribution and use in source and binary forms, with or without
1606 * modification, are permitted provided that the following conditions
1607 * are met:
1608 * 1. Redistributions of source code must retain the above copyright
1609 * notice, this list of conditions and the following disclaimer.
1610 * 2. Redistributions in binary form must reproduce the above copyright
1611 * notice, this list of conditions and the following disclaimer in the
1612 * documentation and/or other materials provided with the distribution.
1613 *
1614 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1615 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1616 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1617 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1618 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1619 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1620 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1621 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1622 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1623 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1624 * POSSIBILITY OF SUCH DAMAGE.
1625 */
1626
1627The preceding notice is from src/is_simh.c in `file`.
1628
1629
1630
1631/*-
1632 * SPDX-License-Identifier: BSD-3-Clause
1633 *
1634 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
1635 * Copyright (c) 1992, 1993, 1994
1636 * The Regents of the University of California. All rights reserved.
1637 *
1638 * This code is derived from software contributed to Berkeley by
1639 * Henry Spencer.
1640 *
1641 * Redistribution and use in source and binary forms, with or without
1642 * modification, are permitted provided that the following conditions
1643 * are met:
1644 * 1. Redistributions of source code must retain the above copyright
1645 * notice, this list of conditions and the following disclaimer.
1646 * 2. Redistributions in binary form must reproduce the above copyright
1647 * notice, this list of conditions and the following disclaimer in the
1648 * documentation and/or other materials provided with the distribution.
1649 * 3. Neither the name of the University nor the names of its contributors
1650 * may be used to endorse or promote products derived from this software
1651 * without specific prior written permission.
1652 *
1653 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1654 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1655 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1656 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1657 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1658 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1659 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1660 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1661 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1662 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1663 * SUCH DAMAGE.
1664 *
1665 * @(#)cname.h 8.3 (Berkeley) 3/20/94
1666 * $FreeBSD: head/lib/libc/regex/cname.h 326025 2017-11-20 19:49:47Z pfg $
1667 */
1668
1669The preceding notice is from src/missing/cname.h in `file`.
1670
1671
1672
1673/*-
1674 * SPDX-License-Identifier: BSD-3-Clause
1675 *
1676 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
1677 * Copyright (c) 1992, 1993, 1994
1678 * The Regents of the University of California. All rights reserved.
1679 *
1680 * This code is derived from software contributed to Berkeley by
1681 * Henry Spencer.
1682 *
1683 * Redistribution and use in source and binary forms, with or without
1684 * modification, are permitted provided that the following conditions
1685 * are met:
1686 * 1. Redistributions of source code must retain the above copyright
1687 * notice, this list of conditions and the following disclaimer.
1688 * 2. Redistributions in binary form must reproduce the above copyright
1689 * notice, this list of conditions and the following disclaimer in the
1690 * documentation and/or other materials provided with the distribution.
1691 * 3. Neither the name of the University nor the names of its contributors
1692 * may be used to endorse or promote products derived from this software
1693 * without specific prior written permission.
1694 *
1695 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1696 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1697 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1698 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1699 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1700 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1701 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1702 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1703 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1704 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1705 * SUCH DAMAGE.
1706 *
1707 * @(#)engine.c 8.5 (Berkeley) 3/20/94
1708 */
1709
1710The preceding notice is from src/missing/engine.c in `file`.
1711
1712
1713
1714/*-
1715 * Copyright (c) 2000 The NetBSD Foundation, Inc.
1716 * All rights reserved.
1717 *
1718 * This code was contributed to The NetBSD Foundation by Allen Briggs.
1719 *
1720 * Redistribution and use in source and binary forms, with or without
1721 * modification, are permitted provided that the following conditions
1722 * are met:
1723 * 1. Redistributions of source code must retain the above copyright
1724 * notice, this list of conditions and the following disclaimer.
1725 * 2. Redistributions in binary form must reproduce the above copyright
1726 * notice, this list of conditions and the following disclaimer in the
1727 * documentation and/or other materials provided with the distribution.
1728 *
1729 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1730 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1731 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1732 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1733 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1734 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1735 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1736 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1737 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1738 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1739 * POSSIBILITY OF SUCH DAMAGE.
1740 */
1741
1742The preceding notice is from src/missing/fmtcheck.c in `file`.
1743
1744
1745
1746/*-
1747 * Copyright (c) 2011 The NetBSD Foundation, Inc.
1748 * All rights reserved.
1749 *
1750 * This code is derived from software contributed to The NetBSD Foundation
1751 * by Christos Zoulas.
1752 *
1753 * Redistribution and use in source and binary forms, with or without
1754 * modification, are permitted provided that the following conditions
1755 * are met:
1756 * 1. Redistributions of source code must retain the above copyright
1757 * notice, this list of conditions and the following disclaimer.
1758 * 2. Redistributions in binary form must reproduce the above copyright
1759 * notice, this list of conditions and the following disclaimer in the
1760 * documentation and/or other materials provided with the distribution.
1761 *
1762 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1763 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1764 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1765 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1766 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1767 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1768 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1769 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1770 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1771 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1772 * POSSIBILITY OF SUCH DAMAGE.
1773 */
1774
1775The preceding notice is from src/missing/getline.c in `file`.
1776
1777
1778
1779/*-
1780 * Copyright (c) 2000 The NetBSD Foundation, Inc.
1781 * All rights reserved.
1782 *
1783 * This code is derived from software contributed to The NetBSD Foundation
1784 * by Dieter Baron and Thomas Klausner.
1785 *
1786 * Redistribution and use in source and binary forms, with or without
1787 * modification, are permitted provided that the following conditions
1788 * are met:
1789 * 1. Redistributions of source code must retain the above copyright
1790 * notice, this list of conditions and the following disclaimer.
1791 * 2. Redistributions in binary form must reproduce the above copyright
1792 * notice, this list of conditions and the following disclaimer in the
1793 * documentation and/or other materials provided with the distribution.
1794 *
1795 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1796 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1797 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1798 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1799 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1800 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1801 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1802 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1803 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1804 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1805 * POSSIBILITY OF SUCH DAMAGE.
1806 */
1807
1808The preceding notice is from src/missing/getopt_long.c and src/mygetopt.h in `file`.
1809
1810
1811
1812/*
1813 * Public domain fallback for reallocarray(3), for platforms (e.g.
1814 * AmigaOS/libnix) whose C library declares it but does not implement it.
1815 */
1816
1817The preceding notice is from src/missing/reallocarray.c in `file`.
1818
1819
1820
1821/*-
1822 * SPDX-License-Identifier: BSD-3-Clause
1823 *
1824 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
1825 * Copyright (c) 1992, 1993, 1994
1826 * The Regents of the University of California. All rights reserved.
1827 *
1828 * Copyright (c) 2011 The FreeBSD Foundation
1829 * All rights reserved.
1830 * Portions of this software were developed by David Chisnall
1831 * under sponsorship from the FreeBSD Foundation.
1832 *
1833 * This code is derived from software contributed to Berkeley by
1834 * Henry Spencer.
1835 *
1836 * Redistribution and use in source and binary forms, with or without
1837 * modification, are permitted provided that the following conditions
1838 * are met:
1839 * 1. Redistributions of source code must retain the above copyright
1840 * notice, this list of conditions and the following disclaimer.
1841 * 2. Redistributions in binary form must reproduce the above copyright
1842 * notice, this list of conditions and the following disclaimer in the
1843 * documentation and/or other materials provided with the distribution.
1844 * 3. Neither the name of the University nor the names of its contributors
1845 * may be used to endorse or promote products derived from this software
1846 * without specific prior written permission.
1847 *
1848 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1849 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1850 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1851 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1852 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1853 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1854 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1855 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1856 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1857 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1858 * SUCH DAMAGE.
1859 *
1860 * @(#)regcomp.c 8.5 (Berkeley) 3/20/94
1861 */
1862
1863The preceding notice is from src/missing/regcomp.c in `file`.
1864
1865
1866
1867/*-
1868 * SPDX-License-Identifier: BSD-3-Clause
1869 *
1870 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
1871 * Copyright (c) 1992, 1993, 1994
1872 * The Regents of the University of California. All rights reserved.
1873 *
1874 * This code is derived from software contributed to Berkeley by
1875 * Henry Spencer.
1876 *
1877 * Redistribution and use in source and binary forms, with or without
1878 * modification, are permitted provided that the following conditions
1879 * are met:
1880 * 1. Redistributions of source code must retain the above copyright
1881 * notice, this list of conditions and the following disclaimer.
1882 * 2. Redistributions in binary form must reproduce the above copyright
1883 * notice, this list of conditions and the following disclaimer in the
1884 * documentation and/or other materials provided with the distribution.
1885 * 3. Neither the name of the University nor the names of its contributors
1886 * may be used to endorse or promote products derived from this software
1887 * without specific prior written permission.
1888 *
1889 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1890 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1891 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1892 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1893 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1894 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1895 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1896 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1897 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1898 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1899 * SUCH DAMAGE.
1900 *
1901 * @(#)regerror.c 8.4 (Berkeley) 3/20/94
1902 */
1903
1904The preceding notice is from src/missing/regerror.c in `file`.
1905
1906
1907
1908$NetBSD: COPYRIGHT,v 1.5 2003/08/07 16:43:19 agc Exp $
1909
1910Copyright 1992, 1993, 1994 Henry Spencer. All rights reserved.
1911This software is not subject to any license of the American Telephone
1912and Telegraph Company or of the Regents of the University of California.
1913
1914Permission is granted to anyone to use this software for any purpose on
1915any computer system, and to alter it and redistribute it, subject
1916to the following restrictions:
1917
19181. The author is not responsible for the consequences of use of this
1919 software, no matter how awful, even if they arise from flaws in it.
1920
19212. The origin of this software must not be misrepresented, either by
1922 explicit claim or by omission. Since few users ever read sources,
1923 credits must appear in the documentation.
1924
19253. Altered versions must be plainly marked as such, and must not be
1926 misrepresented as being the original software. Since few users
1927 ever read sources, credits must appear in the documentation.
1928
19294. This notice may not be removed or altered.
1930
1931=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1932/*-
1933 * Copyright (c) 1994
1934 * The Regents of the University of California. All rights reserved.
1935 *
1936 * Redistribution and use in source and binary forms, with or without
1937 * modification, are permitted provided that the following conditions
1938 * are met:
1939 * 1. Redistributions of source code must retain the above copyright
1940 * notice, this list of conditions and the following disclaimer.
1941 * 2. Redistributions in binary form must reproduce the above copyright
1942 * notice, this list of conditions and the following disclaimer in the
1943 * documentation and/or other materials provided with the distribution.
1944 * 3. Neither the name of the University nor the names of its contributors
1945 * may be used to endorse or promote products derived from this software
1946 * without specific prior written permission.
1947 *
1948 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1949 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1950 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1951 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1952 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1953 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1954 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1955 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1956 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1957 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1958 * SUCH DAMAGE.
1959 *
1960 * @(#)COPYRIGHT 8.1 (Berkeley) 3/16/94
1961 */
1962
1963The preceding notice is from src/missing/REGEX-COPYRIGHT in `file`.
1964
1965
1966
1967/*-
1968 * SPDX-License-Identifier: BSD-3-Clause
1969 *
1970 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
1971 * Copyright (c) 1992, 1993, 1994
1972 * The Regents of the University of California. All rights reserved.
1973 *
1974 * This code is derived from software contributed to Berkeley by
1975 * Henry Spencer.
1976 *
1977 * Redistribution and use in source and binary forms, with or without
1978 * modification, are permitted provided that the following conditions
1979 * are met:
1980 * 1. Redistributions of source code must retain the above copyright
1981 * notice, this list of conditions and the following disclaimer.
1982 * 2. Redistributions in binary form must reproduce the above copyright
1983 * notice, this list of conditions and the following disclaimer in the
1984 * documentation and/or other materials provided with the distribution.
1985 * 3. Neither the name of the University nor the names of its contributors
1986 * may be used to endorse or promote products derived from this software
1987 * without specific prior written permission.
1988 *
1989 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1990 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1991 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1992 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1993 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1994 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1995 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1996 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1997 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1998 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1999 * SUCH DAMAGE.
2000 *
2001 * @(#)regex2.h 8.4 (Berkeley) 3/20/94
2002 * $FreeBSD: head/lib/libc/regex/regex2.h 368359 2020-12-05 03:18:48Z kevans $
2003 */
2004
2005The preceding notice is from src/missing/regex2.h in `file`.
2006
2007
2008
2009/*-
2010 * SPDX-License-Identifier: BSD-3-Clause
2011 *
2012 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2013 * Copyright (c) 1992, 1993, 1994
2014 * The Regents of the University of California. All rights reserved.
2015 *
2016 * This code is derived from software contributed to Berkeley by
2017 * Henry Spencer.
2018 *
2019 * Redistribution and use in source and binary forms, with or without
2020 * modification, are permitted provided that the following conditions
2021 * are met:
2022 * 1. Redistributions of source code must retain the above copyright
2023 * notice, this list of conditions and the following disclaimer.
2024 * 2. Redistributions in binary form must reproduce the above copyright
2025 * notice, this list of conditions and the following disclaimer in the
2026 * documentation and/or other materials provided with the distribution.
2027 * 3. Neither the name of the University nor the names of its contributors
2028 * may be used to endorse or promote products derived from this software
2029 * without specific prior written permission.
2030 *
2031 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2032 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2033 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2034 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2035 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2036 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2037 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2038 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2039 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2040 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2041 * SUCH DAMAGE.
2042 *
2043 * @(#)regexec.c 8.3 (Berkeley) 3/20/94
2044 */
2045
2046The preceding notice is from src/missing/regexec.c in `file`.
2047
2048
2049
2050/*-
2051 * SPDX-License-Identifier: BSD-3-Clause
2052 *
2053 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2054 * Copyright (c) 1992, 1993, 1994
2055 * The Regents of the University of California. All rights reserved.
2056 *
2057 * This code is derived from software contributed to Berkeley by
2058 * Henry Spencer.
2059 *
2060 * Redistribution and use in source and binary forms, with or without
2061 * modification, are permitted provided that the following conditions
2062 * are met:
2063 * 1. Redistributions of source code must retain the above copyright
2064 * notice, this list of conditions and the following disclaimer.
2065 * 2. Redistributions in binary form must reproduce the above copyright
2066 * notice, this list of conditions and the following disclaimer in the
2067 * documentation and/or other materials provided with the distribution.
2068 * 3. Neither the name of the University nor the names of its contributors
2069 * may be used to endorse or promote products derived from this software
2070 * without specific prior written permission.
2071 *
2072 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2073 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2074 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2075 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2076 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2077 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2078 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2079 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2080 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2081 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2082 * SUCH DAMAGE.
2083 *
2084 * @(#)regfree.c 8.3 (Berkeley) 3/20/94
2085 */
2086
2087The preceding notice is from src/missing/regfree.c in `file`.
2088
2089
2090
2091/*-
2092 * Copyright (c) 1990, 1993
2093 * The Regents of the University of California. All rights reserved.
2094 *
2095 * This code is derived from software contributed to Berkeley by
2096 * Chris Torek.
2097 *
2098 * Redistribution and use in source and binary forms, with or without
2099 * modification, are permitted provided that the following conditions
2100 * are met:
2101 * 1. Redistributions of source code must retain the above copyright
2102 * notice, this list of conditions and the following disclaimer.
2103 * 2. Redistributions in binary form must reproduce the above copyright
2104 * notice, this list of conditions and the following disclaimer in the
2105 * documentation and/or other materials provided with the distribution.
2106 * 3. Neither the name of the University nor the names of its contributors
2107 * may be used to endorse or promote products derived from this software
2108 * without specific prior written permission.
2109 *
2110 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2111 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2112 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2113 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2114 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2115 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2116 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2117 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2118 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2119 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2120 * SUCH DAMAGE.
2121 */
2122
2123The preceding notice is from src/missing/strcasestr.c in `file`.
2124
2125
2126
2127/*
2128 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
2129 *
2130 * Permission to use, copy, modify, and distribute this software for any
2131 * purpose with or without fee is hereby granted, provided that the above
2132 * copyright notice and this permission notice appear in all copies.
2133 *
2134 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
2135 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
2136 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
2137 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2138 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
2139 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
2140 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2141 */
2142
2143The preceding notice is from src/missing/strlcat.c and src/missing/strlcpy.c in `file`.
2144
2145
2146
2147/*-
2148 * SPDX-License-Identifier: BSD-3-Clause
2149 *
2150 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2151 * Copyright (c) 1992, 1993, 1994
2152 * The Regents of the University of California. All rights reserved.
2153 *
2154 * This code is derived from software contributed to Berkeley by
2155 * Henry Spencer.
2156 *
2157 * Redistribution and use in source and binary forms, with or without
2158 * modification, are permitted provided that the following conditions
2159 * are met:
2160 * 1. Redistributions of source code must retain the above copyright
2161 * notice, this list of conditions and the following disclaimer.
2162 * 2. Redistributions in binary form must reproduce the above copyright
2163 * notice, this list of conditions and the following disclaimer in the
2164 * documentation and/or other materials provided with the distribution.
2165 * 3. Neither the name of the University nor the names of its contributors
2166 * may be used to endorse or promote products derived from this software
2167 * without specific prior written permission.
2168 *
2169 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2170 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2171 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2172 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2173 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2174 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2175 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2176 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2177 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2178 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2179 * SUCH DAMAGE.
2180 *
2181 * @(#)utils.h 8.3 (Berkeley) 3/20/94
2182 * $FreeBSD: head/lib/libc/regex/utils.h 341838 2018-12-12 04:23:00Z yuripv $
2183 */
2184
2185The preceding notice is from src/missing/utils.h in `file`.
2186
2187
2188
2189/*-
2190 * Copyright (c) 2008, 2016 Christos Zoulas
2191 * All rights reserved.
2192 *
2193 * Redistribution and use in source and binary forms, with or without
2194 * modification, are permitted provided that the following conditions
2195 * are met:
2196 * 1. Redistributions of source code must retain the above copyright
2197 * notice, this list of conditions and the following disclaimer.
2198 * 2. Redistributions in binary form must reproduce the above copyright
2199 * notice, this list of conditions and the following disclaimer in the
2200 * documentation and/or other materials provided with the distribution.
2201 *
2202 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2203 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2204 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2205 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2206 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2207 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2208 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2209 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2210 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2211 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2212 * POSSIBILITY OF SUCH DAMAGE.
2213 */
2214
2215The preceding notice is from src/readcdf.c in `file`.
2216
2217
2218
2219/*-
2220 * Copyright (c) 1992 Henry Spencer.
2221 * Copyright (c) 1992, 1993
2222 * The Regents of the University of California. All rights reserved.
2223 *
2224 * This code is derived from software contributed to Berkeley by
2225 * Henry Spencer of the University of Toronto.
2226 *
2227 * Redistribution and use in source and binary forms, with or without
2228 * modification, are permitted provided that the following conditions
2229 * are met:
2230 * 1. Redistributions of source code must retain the above copyright
2231 * notice, this list of conditions and the following disclaimer.
2232 * 2. Redistributions in binary form must reproduce the above copyright
2233 * notice, this list of conditions and the following disclaimer in the
2234 * documentation and/or other materials provided with the distribution.
2235 * 3. Neither the name of the University nor the names of its contributors
2236 * may be used to endorse or promote products derived from this software
2237 * without specific prior written permission.
2238 *
2239 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2240 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2241 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2242 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2243 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2244 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2245 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2246 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2247 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2248 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2249 * SUCH DAMAGE.
2250 *
2251 * @(#)regex.h 8.2 (Berkeley) 1/3/94
2252 * $FreeBSD: src/include/regex.h,v 1.12 2010/02/16 19:39:50 imp Exp $
2253 */
2254
2255The preceding notice is from src/regex-bsd.h in `file`.
2256*/
2257/*
2258
2259Text of LICENSE from DROID:
2260
2261Copyright (c) 2016, The National Archives <pronom@nationalarchives.gov.uk>
2262All rights reserved.
2263
2264Redistribution and use in source and binary forms, with or without
2265modification, are permitted provided that the following
2266conditions are met:
2267
2268 * Redistributions of source code must retain the above copyright
2269 notice, this list of conditions and the following disclaimer.
2270
2271 * Redistributions in binary form must reproduce the above copyright
2272 notice, this list of conditions and the following disclaimer in the
2273 documentation and/or other materials provided with the distribution.
2274
2275 * Neither the name of the The National Archives nor the
2276 names of its contributors may be used to endorse or promote products
2277 derived from this software without specific prior written permission.
2278
2279THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2280AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2281IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2282PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
2283CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2284EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2285PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2286PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2287LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2288NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2289SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2290*/
2291
2292/*
2293
2294Text of LICENSE from fileid:
2295
2296The MIT License (MIT)
2297
2298Copyright (c) 2015 David B Heise
2299
2300Permission is hereby granted, free of charge, to any person obtaining a copy of
2301this software and associated documentation files (the "Software"), to deal in
2302the Software without restriction, including without limitation the rights to
2303use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
2304the Software, and to permit persons to whom the Software is furnished to do so,
2305subject to the following conditions:
2306
2307The above copyright notice and this permission notice shall be included in all
2308copies or substantial portions of the Software.
2309
2310THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2311IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
2312FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
2313COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
2314IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2315CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2316
2317
2318*/
2319
2320/*
2321Text of LICENSE from binwalk:
2322
2323
2324MIT License
2325
2326Copyright (c) 2024 devttys0
2327
2328Permission is hereby granted, free of charge, to any person obtaining a copy
2329of this software and associated documentation files (the "Software"), to deal
2330in the Software without restriction, including without limitation the rights
2331to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2332copies of the Software, and to permit persons to whom the Software is
2333furnished to do so, subject to the following conditions:
2334
2335The above copyright notice and this permission notice shall be included in all
2336copies or substantial portions of the Software.
2337
2338THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2339IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2340FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2341AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2342LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2343OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2344SOFTWARE.
2345
2346*/
2347
2348/*
2349Text of LICENSE from polyfile:
2350
2351
2352 Apache License
2353 Version 2.0, January 2004
2354 http://www.apache.org/licenses/
2355
2356 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
2357
2358 1. Definitions.
2359
2360 "License" shall mean the terms and conditions for use, reproduction,
2361 and distribution as defined by Sections 1 through 9 of this document.
2362
2363 "Licensor" shall mean the copyright owner or entity authorized by
2364 the copyright owner that is granting the License.
2365
2366 "Legal Entity" shall mean the union of the acting entity and all
2367 other entities that control, are controlled by, or are under common
2368 control with that entity. For the purposes of this definition,
2369 "control" means (i) the power, direct or indirect, to cause the
2370 direction or management of such entity, whether by contract or
2371 otherwise, or (ii) ownership of fifty percent (50%) or more of the
2372 outstanding shares, or (iii) beneficial ownership of such entity.
2373
2374 "You" (or "Your") shall mean an individual or Legal Entity
2375 exercising permissions granted by this License.
2376
2377 "Source" form shall mean the preferred form for making modifications,
2378 including but not limited to software source code, documentation
2379 source, and configuration files.
2380
2381 "Object" form shall mean any form resulting from mechanical
2382 transformation or translation of a Source form, including but
2383 not limited to compiled object code, generated documentation,
2384 and conversions to other media types.
2385
2386 "Work" shall mean the work of authorship, whether in Source or
2387 Object form, made available under the License, as indicated by a
2388 copyright notice that is included in or attached to the work
2389 (an example is provided in the Appendix below).
2390
2391 "Derivative Works" shall mean any work, whether in Source or Object
2392 form, that is based on (or derived from) the Work and for which the
2393 editorial revisions, annotations, elaborations, or other modifications
2394 represent, as a whole, an original work of authorship. For the purposes
2395 of this License, Derivative Works shall not include works that remain
2396 separable from, or merely link (or bind by name) to the interfaces of,
2397 the Work and Derivative Works thereof.
2398
2399 "Contribution" shall mean any work of authorship, including
2400 the original version of the Work and any modifications or additions
2401 to that Work or Derivative Works thereof, that is intentionally
2402 submitted to Licensor for inclusion in the Work by the copyright owner
2403 or by an individual or Legal Entity authorized to submit on behalf of
2404 the copyright owner. For the purposes of this definition, "submitted"
2405 means any form of electronic, verbal, or written communication sent
2406 to the Licensor or its representatives, including but not limited to
2407 communication on electronic mailing lists, source code control systems,
2408 and issue tracking systems that are managed by, or on behalf of, the
2409 Licensor for the purpose of discussing and improving the Work, but
2410 excluding communication that is conspicuously marked or otherwise
2411 designated in writing by the copyright owner as "Not a Contribution."
2412
2413 "Contributor" shall mean Licensor and any individual or Legal Entity
2414 on behalf of whom a Contribution has been received by Licensor and
2415 subsequently incorporated within the Work.
2416
2417 2. Grant of Copyright License. Subject to the terms and conditions of
2418 this License, each Contributor hereby grants to You a perpetual,
2419 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
2420 copyright license to reproduce, prepare Derivative Works of,
2421 publicly display, publicly perform, sublicense, and distribute the
2422 Work and such Derivative Works in Source or Object form.
2423
2424 3. Grant of Patent License. Subject to the terms and conditions of
2425 this License, each Contributor hereby grants to You a perpetual,
2426 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
2427 (except as stated in this section) patent license to make, have made,
2428 use, offer to sell, sell, import, and otherwise transfer the Work,
2429 where such license applies only to those patent claims licensable
2430 by such Contributor that are necessarily infringed by their
2431 Contribution(s) alone or by combination of their Contribution(s)
2432 with the Work to which such Contribution(s) was submitted. If You
2433 institute patent litigation against any entity (including a
2434 cross-claim or counterclaim in a lawsuit) alleging that the Work
2435 or a Contribution incorporated within the Work constitutes direct
2436 or contributory patent infringement, then any patent licenses
2437 granted to You under this License for that Work shall terminate
2438 as of the date such litigation is filed.
2439
2440 4. Redistribution. You may reproduce and distribute copies of the
2441 Work or Derivative Works thereof in any medium, with or without
2442 modifications, and in Source or Object form, provided that You
2443 meet the following conditions:
2444
2445 (a) You must give any other recipients of the Work or
2446 Derivative Works a copy of this License; and
2447
2448 (b) You must cause any modified files to carry prominent notices
2449 stating that You changed the files; and
2450
2451 (c) You must retain, in the Source form of any Derivative Works
2452 that You distribute, all copyright, patent, trademark, and
2453 attribution notices from the Source form of the Work,
2454 excluding those notices that do not pertain to any part of
2455 the Derivative Works; and
2456
2457 (d) If the Work includes a "NOTICE" text file as part of its
2458 distribution, then any Derivative Works that You distribute must
2459 include a readable copy of the attribution notices contained
2460 within such NOTICE file, excluding those notices that do not
2461 pertain to any part of the Derivative Works, in at least one
2462 of the following places: within a NOTICE text file distributed
2463 as part of the Derivative Works; within the Source form or
2464 documentation, if provided along with the Derivative Works; or,
2465 within a display generated by the Derivative Works, if and
2466 wherever such third-party notices normally appear. The contents
2467 of the NOTICE file are for informational purposes only and
2468 do not modify the License. You may add Your own attribution
2469 notices within Derivative Works that You distribute, alongside
2470 or as an addendum to the NOTICE text from the Work, provided
2471 that such additional attribution notices cannot be construed
2472 as modifying the License.
2473
2474 You may add Your own copyright statement to Your modifications and
2475 may provide additional or different license terms and conditions
2476 for use, reproduction, or distribution of Your modifications, or
2477 for any such Derivative Works as a whole, provided Your use,
2478 reproduction, and distribution of the Work otherwise complies with
2479 the conditions stated in this License.
2480
2481 5. Submission of Contributions. Unless You explicitly state otherwise,
2482 any Contribution intentionally submitted for inclusion in the Work
2483 by You to the Licensor shall be under the terms and conditions of
2484 this License, without any additional terms or conditions.
2485 Notwithstanding the above, nothing herein shall supersede or modify
2486 the terms of any separate license agreement you may have executed
2487 with Licensor regarding such Contributions.
2488
2489 6. Trademarks. This License does not grant permission to use the trade
2490 names, trademarks, service marks, or product names of the Licensor,
2491 except as required for reasonable and customary use in describing the
2492 origin of the Work and reproducing the content of the NOTICE file.
2493
2494 7. Disclaimer of Warranty. Unless required by applicable law or
2495 agreed to in writing, Licensor provides the Work (and each
2496 Contributor provides its Contributions) on an "AS IS" BASIS,
2497 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
2498 implied, including, without limitation, any warranties or conditions
2499 of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
2500 PARTICULAR PURPOSE. You are solely responsible for determining the
2501 appropriateness of using or redistributing the Work and assume any
2502 risks associated with Your exercise of permissions under this License.
2503
2504 8. Limitation of Liability. In no event and under no legal theory,
2505 whether in tort (including negligence), contract, or otherwise,
2506 unless required by applicable law (such as deliberate and grossly
2507 negligent acts) or agreed to in writing, shall any Contributor be
2508 liable to You for damages, including any direct, indirect, special,
2509 incidental, or consequential damages of any character arising as a
2510 result of this License or out of the use or inability to use the
2511 Work (including but not limited to damages for loss of goodwill,
2512 work stoppage, computer failure or malfunction, or any and all
2513 other commercial damages or losses), even if such Contributor
2514 has been advised of the possibility of such damages.
2515
2516 9. Accepting Warranty or Additional Liability. While redistributing
2517 the Work or Derivative Works thereof, You may choose to offer,
2518 and charge a fee for, acceptance of support, warranty, indemnity,
2519 or other liability obligations and/or rights consistent with this
2520 License. However, in accepting such obligations, You may act only
2521 on Your own behalf and on Your sole responsibility, not on behalf
2522 of any other Contributor, and only if You agree to indemnify,
2523 defend, and hold each Contributor harmless for any liability
2524 incurred by, or claims asserted against, such Contributor by reason
2525 of your accepting any such warranty or additional liability.
2526
2527 END OF TERMS AND CONDITIONS
2528
2529 APPENDIX: How to apply the Apache License to your work.
2530
2531 To apply the Apache License to your work, attach the following
2532 boilerplate notice, with the fields enclosed by brackets "[]"
2533 replaced with your own identifying information. (Don't include
2534 the brackets!) The text should be enclosed in the appropriate
2535 comment syntax for the file format. We also recommend that a
2536 file or class name and description of purpose be included on the
2537 same "printed page" as the copyright notice for easier
2538 identification within third-party archives.
2539
2540 Copyright [yyyy] [name of copyright owner]
2541
2542 Licensed under the Apache License, Version 2.0 (the "License");
2543 you may not use this file except in compliance with the License.
2544 You may obtain a copy of the License at
2545
2546 http://www.apache.org/licenses/LICENSE-2.0
2547
2548 Unless required by applicable law or agreed to in writing, software
2549 distributed under the License is distributed on an "AS IS" BASIS,
2550 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2551 See the License for the specific language governing permissions and
2552 limitations under the License.
2553
2554*/