mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-23 19:11:46 +01:00
* Port Java class source: Craft Anything Source: storytold/craft-anything@f64ae3bf3c * Port Java class source: Find class usage in multidimensional object arrays (R0.5) (#437) Source: storytold/craft-anything@ffe15c9165 * Port Java class source: More format parsers keep to their declared lengths and refuse impossible values (#722) Source: storytold/craft-anything@b9ca099903 * Port Java class source: Address the parser review findings from #722 (#766) Source: storytold/craft-anything@eab6a0f01b * Port Java class source: Read JVM method parameters containing parentheses in class names (R3.12) (#1342) Source: storytold/craft-anything@fb4c437fe6 * Port Java class source: Reject Java constants that exceed the constant-pool slots (R3.12) (#1373) Source: storytold/craft-anything@1c4f233f08 * Port Java class source: Validate JVM switch tables before allocating decoded pairs (R3.12) (#1503) Source: storytold/craft-anything@b40c56ef5c * Port Java class source: Reuse constant-pool names while reading Java attributes (R3.12) (#1549) Source: storytold/craft-anything@76fcdaadb7 * Port Java class source: Trace JVM bootstrap dependencies at their bytecode use sites (R3.12) (#1648) Source: storytold/craft-anything@c5e524dd08 * Port Java class source: Reject impossible JVM array allocation operands (R3.12) (#1675) Source: storytold/craft-anything@f04d7456e0 * Port Java class source: Report truncated Java class attribute tables (R3.12) Source: storytold/craft-anything@420552ff74 * Expose neutral Java class API and retain checked reader and synthetic fixtures * Retain Java regression: java_array_operands Source: storytold/craft-anything@f04d7456e0 * Retain Java regression: java_attribute_names Source: storytold/craft-anything@76fcdaadb7 * Retain Java regression: java_constant_pool_slots Source: storytold/craft-anything@1c4f233f08 * Retain Java regression: java_invoke_operands Source: storytold/craft-anything@eab6a0f01b * Retain Java regression: java_linkage_references Source: storytold/craft-anything@c5e524dd08 * Retain Java regression: java_truncated_attributes Source: storytold/craft-anything@420552ff74 * Retain Java regression: java_wide_opcodes Source: storytold/craft-anything@b9ca099903 * Register Java class reader and retain source regression coverage --------- Co-authored-by: Brandon Thomas <echelon@gmail.com> Co-authored-by: Afloat <132809511+Afloat16@users.noreply.github.com> Co-authored-by: BFlat <bombayapirat@gmail.com> Co-authored-by: Afloat <ShuffleMonkey@163.com> Co-authored-by: RRFZ <247457381+Plastic-time@users.noreply.github.com>
49 lines
1.7 KiB
Rust
49 lines
1.7 KiB
Rust
use crate::java_ops::{decode, decode_one};
|
|
|
|
#[test]
|
|
fn invalid_primitive_array_types_stop_before_the_allocation() {
|
|
for atype in (0..=u8::MAX).filter(|value| !(4..=11).contains(value)) {
|
|
assert!(decode_one(&[0xbc, atype], 0).is_none(), "atype {atype}");
|
|
let (instructions, complete) = decode(&[0, 0xbc, atype, 0xb1], 100);
|
|
assert!(!complete, "atype {atype}");
|
|
assert_eq!(instructions.len(), 1);
|
|
assert_eq!(instructions[0].name, "nop");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn zero_dimension_multidimensional_allocations_are_not_complete_bytecode() {
|
|
assert!(decode_one(&[0xc5, 0, 1, 0], 0).is_none());
|
|
let (instructions, complete) = decode(&[0, 0xc5, 0, 1, 0, 0xb1], 100);
|
|
assert!(!complete);
|
|
assert_eq!(instructions.len(), 1);
|
|
assert_eq!(instructions[0].name, "nop");
|
|
}
|
|
|
|
#[test]
|
|
fn every_defined_primitive_type_and_nonzero_dimension_remains_decodable() {
|
|
for atype in 4..=11 {
|
|
let (instructions, complete) = decode(&[0xbc, atype, 0xb1], 100);
|
|
assert!(complete);
|
|
assert_eq!(instructions.len(), 2);
|
|
assert_eq!(instructions[0].int, Some(i32::from(atype)));
|
|
assert_eq!(instructions[0].len, 2);
|
|
}
|
|
for dimensions in 1..=u8::MAX {
|
|
let instruction = decode_one(&[0, 0xc5, 0x12, 0x34, dimensions], 1).unwrap();
|
|
assert_eq!(instruction.pc, 1);
|
|
assert_eq!(instruction.cp_index, Some(0x1234));
|
|
assert_eq!(instruction.int, Some(i32::from(dimensions)));
|
|
assert_eq!(instruction.len, 4);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn incomplete_array_operands_remain_rejected() {
|
|
for instruction in [&[0xbc, 10][..], &[0xc5, 0, 1, 2][..]] {
|
|
for end in 1..instruction.len() {
|
|
assert!(decode_one(&instruction[..end], 0).is_none());
|
|
}
|
|
}
|
|
}
|