]> git.donarmstrong.com Git - perltidy.git/commitdiff
check size of files arriving from stdin
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 29 Oct 2023 01:22:53 +0000 (18:22 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 29 Oct 2023 01:22:53 +0000 (18:22 -0700)
bin/perltidy
lib/Perl/Tidy.pm

index 0a3741ea32ce7d1abfab98d0b279411423c29258..0bf970f5527cc962eaca0b1f43e3f8a67392054e 100755 (executable)
@@ -5343,7 +5343,10 @@ MB for example would be
 
   perltidy -maxfs=20
 
-This only applies to files specified by filename on the command line.
+This length test is applied to named files before they are read into memory.
+It is applied to files arriving from standard input after they are read into
+memory. It is not applied to character strings arriving by a call to the
+Perl::Tidy module.
 
 B<--maximum-level-errors=n> or B<-maxle=n> specifies the maximum number of
 indentation level errors are allowed before perltidy skips formatting and just
index ef043b4f061701d3b61f9568079156d393833d5d..70c6e35d4fc8defb129c35778bd2d4d857619214 100644 (file)
@@ -1573,6 +1573,21 @@ sub get_decoded_string_buffer {
         # zero length, but keep going
     }
 
+    # Check size of strings arriving from the standard input. These
+    # could not be checked until now.
+    if ( $input_file eq '-' ) {
+        my $size_in_mb =
+          length( ${$rinput_string} ) / ( CONST_1024 * CONST_1024 );
+        my $maximum_file_size_mb = $rOpts->{'maximum-file-size-mb'};
+        if ( $size_in_mb > $maximum_file_size_mb ) {
+            $size_in_mb = sprintf( "%0.1f", $size_in_mb );
+            Warn(
+"skipping file: <stdin>: size $size_in_mb MB exceeds limit $maximum_file_size_mb; use -maxfs=i to change\n"
+            );
+            return;
+        }
+    }
+
     $rinput_string = $self->set_line_separator($rinput_string);
 
     my $encoding_in              = EMPTY_STRING;
@@ -2013,10 +2028,11 @@ sub process_all_files {
             # files into memory, trying to process an extremely large file
             # could cause system problems.
             my $size_in_mb = ( -s $input_file ) / ( CONST_1024 * CONST_1024 );
-            if ( $size_in_mb > $rOpts->{'maximum-file-size-mb'} ) {
+            my $maximum_file_size_mb = $rOpts->{'maximum-file-size-mb'};
+            if ( $size_in_mb > $maximum_file_size_mb ) {
                 $size_in_mb = sprintf( "%0.1f", $size_in_mb );
                 Warn(
-"skipping file: $input_file: size $size_in_mb MB exceeds limit $rOpts->{'maximum-file-size-mb'}; use -mfs=i to change\n"
+"skipping file: $input_file: size $size_in_mb MB exceeds limit $maximum_file_size_mb; use -maxfs=i to change\n"
                 );
                 next;
             }