<commit_before><?php
$tool_user_name = 'convert';

include_once ( 'shared/common.php' ) ;
error_reporting( E_ALL & ~E_NOTICE ); # Don't clutter the directory with unhelpful stuff

$host = getProtocol() . "://tools.wmflabs.org/$tool_user_name/";

if ( !array_key_exists( 'file', $_FILES ) ) {
  header( "Location: $host" );
  die();
}
$uploadName = $_FILES['file']['tmp_name'];
$fileName = $uploadName . '.pdf';
$targetName = $fileName . '.svg';

if ( $_FILES['file']['size'] > 1000000 ) {
  unlink( $uploadName );
  header( "Location: $host#tooBig" );
  die();
}

if ( !move_uploaded_file( $uploadName, $fileName ) ) {
  echo( 'cant move uploaded file' );
  unlink( $uploadName );
  header( "Location: $host#cantmove" );
  die();
}

exec( 'pdf2svg ' . escapeshellarg( $fileName ) . ' ' . escapeshellarg( $targetName ) );
unlink( $fileName );

$handle = fopen( $targetName, 'r' );

if ( $handle === false ) {
  echo( 'error converting the file' );
  header( "Location: $host#conversionError" );
  die();
}

if ( filesize( $targetName ) > 5000000 ) {
  fclose( $handle );
  unlink( $targetName );
  echo( 'output unexpectedly huge' );
  header( "Location: $host#outputTooHuge" );
  die();
}

$content = file_get_contents( $targetName );
fclose( $handle );
unlink( $targetName );

if ( strlen( $content ) > 5000000 ) {
  echo( 'output unexpectedly huge 2' );
  header( "Location: $host#outputTooHuge2" );
  die();
}

header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Content-type: image/svg+xml' );
header( 'Content-Disposition: attachment; filename="' . addslashes( $_FILES['file']['name'] ) . '.svg"' );
echo $content;
die();<commit_msg>do header() calls before the echo output<commit_after><?php
$tool_user_name = 'convert';

include_once ( 'shared/common.php' ) ;
error_reporting( E_ALL & ~E_NOTICE ); # Don't clutter the directory with unhelpful stuff

$url = getProtocol() . "://tools.wmflabs.org/$tool_user_name/";

if ( !array_key_exists( 'file', $_FILES ) ) {
  header( "Location: $url" );
  die();
}
$uploadName = $_FILES['file']['tmp_name'];
$fileName = $uploadName . '.pdf';
$targetName = $fileName . '.svg';

if ( $_FILES['file']['size'] > 1000000 ) {
  unlink( $uploadName );
  header( "Location: $url#tooBig" );
  die();
}

if ( !move_uploaded_file( $uploadName, $fileName ) ) {
  unlink( $uploadName );
  header( "Location: $url#cantmove" );
  echo( 'cant move uploaded file' );
  die();
}

exec( 'pdf2svg ' . escapeshellarg( $fileName ) . ' ' . escapeshellarg( $targetName ) );
unlink( $fileName );

$handle = fopen( $targetName, 'r' );

if ( $handle === false ) {
  header( "Location: $url#conversionError" );
  echo( 'error converting the file' );
  die();
}

if ( filesize( $targetName ) > 5000000 ) {
  fclose( $handle );
  unlink( $targetName );
  header( "Location: $url#outputTooHuge" );
  echo( 'output unexpectedly huge' );
  die();
}

$content = file_get_contents( $targetName );
fclose( $handle );
unlink( $targetName );

if ( strlen( $content ) > 5000000 ) {
  header( "Location: $url#outputTooHuge2" );
  echo( 'output unexpectedly huge 2' );
  die();
}

header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Content-type: image/svg+xml' );
header( 'Content-Disposition: attachment; filename="' . addslashes( $_FILES['file']['name'] ) . '.svg"' );
echo $content;
die();
{'fraction_non_alphanumeric': 0.1951073985680191, 'fraction_numerical': 0.015513126491646777, 'mean_word_length': 4.61641541038526, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5231883', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1189, 'n_words': 277}