[ASE File In] Fix crash when loading aseprite file with mismatched palette data.

This commit is contained in:
Tanasart 2024-12-25 08:50:08 +07:00
parent e4aa459571
commit 778a1474c7
2 changed files with 29 additions and 25 deletions

View file

@ -156,8 +156,8 @@ globalvar __ase_format_chunk_color_profile; __ase_format_chunk_color_profile = [
[_BIN_TYPE.word, "Flag"], //1: Fix gamma [_BIN_TYPE.word, "Flag"], //1: Fix gamma
[_BIN_TYPE.fixed, "Fixed gamma"], [_BIN_TYPE.fixed, "Fixed gamma"],
[_BIN_TYPE.byte, "Unused", 8], [_BIN_TYPE.byte, "Unused", 8],
[_BIN_TYPE.dword, "ICC Data length", 1, function(chunk) { return chunk[$ "Type"] == 2; }], [_BIN_TYPE.dword, "ICC Data length", 1, function(c) /*=>*/ {return c[$ "Type"] == 2}],
[_BIN_TYPE.byte, "ICC Data", "ICC Data length", function(chunk) { return chunk[$ "Type"] == 2; }], [_BIN_TYPE.byte, "ICC Data", "ICC Data length", function(c) /*=>*/ {return c[$ "Type"] == 2}],
]; ];
globalvar __ase_format_chunk_file; __ase_format_chunk_file = [ globalvar __ase_format_chunk_file; __ase_format_chunk_file = [
@ -201,16 +201,16 @@ globalvar __ase_format_chunk_palette_entry; __ase_format_chunk_palette_entry = [
[_BIN_TYPE.byte, "Green"], [_BIN_TYPE.byte, "Green"],
[_BIN_TYPE.byte, "Blue"], [_BIN_TYPE.byte, "Blue"],
[_BIN_TYPE.byte, "Alpha"], [_BIN_TYPE.byte, "Alpha"],
[_BIN_TYPE.string, "Name", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 0); }], [_BIN_TYPE.string, "Name", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 0)}],
]; ];
globalvar __ase_format_chunk_user_data; __ase_format_chunk_user_data = [ globalvar __ase_format_chunk_user_data; __ase_format_chunk_user_data = [
[_BIN_TYPE.dword, "Flag"], //1: Text, 2: Color, 4: Properties [_BIN_TYPE.dword, "Flag"], //1: Text, 2: Color, 4: Properties
[_BIN_TYPE.string, "Name", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 0); }], [_BIN_TYPE.string, "Name", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 0)} ],
[_BIN_TYPE.byte, "Red", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], [_BIN_TYPE.byte, "Red", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 1)} ],
[_BIN_TYPE.byte, "Green", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], [_BIN_TYPE.byte, "Green", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 1)} ],
[_BIN_TYPE.byte, "Blue", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], [_BIN_TYPE.byte, "Blue", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 1)} ],
[_BIN_TYPE.byte, "Alpha", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], [_BIN_TYPE.byte, "Alpha", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 1)} ],
]; ];
globalvar __ase_format_chunk_user_data_prop; __ase_format_chunk_user_data_prop = [ globalvar __ase_format_chunk_user_data_prop; __ase_format_chunk_user_data_prop = [
@ -256,10 +256,10 @@ globalvar __ase_format_chunk_tileset; __ase_format_chunk_tileset = [
[_BIN_TYPE.short, "Base index"], [_BIN_TYPE.short, "Base index"],
[_BIN_TYPE.byte, "Reserved", 14], [_BIN_TYPE.byte, "Reserved", 14],
[_BIN_TYPE.string, "Name"], [_BIN_TYPE.string, "Name"],
[_BIN_TYPE.dword, "ID of external file", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], [_BIN_TYPE.dword, "ID of external file", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 1)} ],
[_BIN_TYPE.dword, "Tileset ID", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 1); }], [_BIN_TYPE.dword, "Tileset ID", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 1)} ],
[_BIN_TYPE.dword, "Data length", 1, function(chunk) { return chunk[$ "Flag"] & (1 << 2); }], [_BIN_TYPE.dword, "Data length", 1, function(c) /*=>*/ {return c[$ "Flag"] & (1 << 2)} ],
[_BIN_TYPE.pixel, "Compressed image", "Data length", function(chunk) { return chunk[$ "Flag"] & (1 << 2); }], [_BIN_TYPE.pixel, "Compressed image", "Data length", function(c) /*=>*/ {return c[$ "Flag"] & (1 << 2)} ],
]; ];
function read_format_type(_bin, datType, outMap) { function read_format_type(_bin, datType, outMap) {

View file

@ -165,15 +165,13 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const
edit_time = 0; edit_time = 0;
attributes.file_checker = true; attributes.file_checker = true;
array_push(attributeEditors, [ "File Watcher", function() { return attributes.file_checker; }, array_push(attributeEditors, [ "File Watcher", function() /*=>*/ {return attributes.file_checker}, new checkBox(function() /*=>*/ { attributes.file_checker = !attributes.file_checker; }) ]);
new checkBox(function() { attributes.file_checker = !attributes.file_checker; }) ]);
content = noone; content = noone;
layers = []; layers = [];
tags = []; tags = [];
_tag_delay = 0; _tag_delay = 0;
path_current = ""; path_current = "";
first_update = false; first_update = false;
on_drop_file = function(path) { on_drop_file = function(path) {
@ -252,24 +250,30 @@ function Node_ASE_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const
switch(chunk[$ "Type"]) { switch(chunk[$ "Type"]) {
case 0x2019: //palette case 0x2019: //palette
var pals = chunk[$ "Palette"]; var pals = chunk[$ "Palette"];
var plt = []; var pamo = array_length(pals)
var plt = array_create(pamo);
var par = array_create(pamo);
for( var k = 0; k < array_length(pals); k++ ) for( var k = 0; k < pamo; k++ ) {
array_push(plt, [ pals[k][$ "Red"], pals[k][$ "Green"], pals[k][$ "Blue"], pals[k][$ "Alpha"] ]); var _clr = pals[k];
var _r = _clr[$ "Red"] ?? 0;
var _g = _clr[$ "Green"] ?? 0;
var _b = _clr[$ "Blue"] ?? 0;
var _a = _clr[$ "Alpha"] ?? 0;
plt[k] = [ _r, _g, _b, _a ];
par[k] = make_color_rgba(_r, _g, _b, _a);
}
content[$ "Palette"] = plt; content[$ "Palette"] = plt;
outputs[3].setValue(par);
var p_arr = [];
for( var k = 0; k < array_length(plt); k++ )
array_push(p_arr, make_color_rgba(plt[k][0], plt[k][1], plt[k][2], plt[k][3]));
outputs[3].setValue(p_arr);
break; break;
case 0x2004: //layer case 0x2004: //layer
var name = chunk[$ "Name"]; var name = chunk[$ "Name"];
var type = chunk[$ "Layer type"];
array_push(layers, new ase_layer(name, chunk[$ "Layer type"])); array_push(layers, new ase_layer(name, type));
array_push(vis, true); array_push(vis, true);
break; break;