49
49
return; \
50
50
}
51
51
52
+ static bool module_are_literals_compressed (const uint8_t * litT );
52
53
#ifdef WITH_ZLIB
53
54
static void * module_uncompress_literals (const uint8_t * litT , int size );
54
55
#endif
@@ -72,6 +73,13 @@ static enum ModuleLoadResult module_populate_atoms_table(Module *this_module, ui
72
73
{
73
74
int atoms_count = READ_32_UNALIGNED (table_data + 8 );
74
75
76
+ if (UNLIKELY (atoms_count < 0 )) {
77
+ fprintf (stderr , "Code compiled with OTP-28 is not supported by this version of AtomVM.\n"
78
+ "Please recompile your code using an earlier version, such as OTP-27,\n"
79
+ "or switch to a newer version of AtomVM, such as a main snapshot.\n" );
80
+ AVM_ABORT ();
81
+ }
82
+
75
83
const char * current_atom = (const char * ) table_data + 12 ;
76
84
77
85
this_module -> local_atoms_to_global_table = calloc (atoms_count + 1 , sizeof (int ));
@@ -284,6 +292,11 @@ Module *module_new_from_iff_binary(GlobalContext *global, const void *iff_binary
284
292
module_parse_line_table (mod , beam_file + offsets [LINT ] + 8 , sizes [LINT ]);
285
293
286
294
if (offsets [LITT ]) {
295
+ if (UNLIKELY (!module_are_literals_compressed (beam_file + offsets [LITT ]))) {
296
+ fprintf (stderr , "Code compiled with OTP-28 is not supported by this version of AtomVM.\n"
297
+ "Please recompile your code using an earlier version, such as OTP-27,\n"
298
+ "or switch to a newer version of AtomVM, such as a main snapshot.\n" );
299
+ }
287
300
#ifdef WITH_ZLIB
288
301
mod -> literals_data = module_uncompress_literals (beam_file + offsets [LITT ], sizes [LITT ]);
289
302
if (IS_NULL_PTR (mod -> literals_data )) {
@@ -364,6 +377,12 @@ COLD_FUNC void module_destroy(Module *module)
364
377
free (module );
365
378
}
366
379
380
+ static bool module_are_literals_compressed (const uint8_t * litT )
381
+ {
382
+ uint32_t required_buf_size = READ_32_ALIGNED (litT + LITT_UNCOMPRESSED_SIZE_OFFSET );
383
+ return (required_buf_size != 0 );
384
+ }
385
+
367
386
#ifdef WITH_ZLIB
368
387
static void * module_uncompress_literals (const uint8_t * litT , int size )
369
388
{
0 commit comments