Kanekonkon commited on
Commit
5baa31c
·
verified ·
1 Parent(s): 61be8af

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +4 -6
  2. checklist/test_sourcecode_001.txt +152 -0
app.py CHANGED
@@ -132,9 +132,8 @@ def extract_text_from_pdf(pdf_file_path):
132
  if page_text:
133
  text += page_text + "\n"
134
  # print(f" Page {i+1} extracted text (first 100 chars): {page_text[:100].replace('\n', ' ')}...")
135
- newline_char = '\n'
136
- print(f" Page {i+1} extracted text (first 100 chars): {page_text[:100].replace(newline_char, ' ')}...")
137
-
138
  else:
139
  print(f" Page {i+1} extracted no text.")
140
 
@@ -266,7 +265,7 @@ def upload_pdf_and_process(pdf_files):
266
 
267
  # --- デバッグ用追加コード (前回のデバッグで追加したものは残しておくと良いでしょう) ---
268
  print(f"DEBUG: raw_text received from extract_text_from_pdf (length: {len(raw_text)})")
269
- print(f"DEBUG: raw_text starts with: '{raw_text[:100].replace(newline_char, ' ')}'")
270
  print(f"DEBUG: 'エラー' in raw_text: {'エラー' in raw_text}")
271
  print(f"DEBUG: '抽出できませんでした' in raw_text: {'抽出できませんでした' in raw_text}")
272
  print(f"DEBUG: 'PDFにページが含まれていません' in raw_text: {'PDFにページが含まれていません' in raw_text}")
@@ -350,7 +349,6 @@ with gr.Blocks() as gradioUI:
350
  利用するLLMを選択してください。
351
  """
352
  )
353
-
354
  with gr.Row():
355
  with gr.Column():
356
  pdf_input = gr.File(label="PDFドキュメントをアップロード", file_types=[".pdf"], file_count="multiple")
@@ -396,7 +394,7 @@ with gr.Blocks() as gradioUI:
396
  review_button.click(
397
  answer_question,
398
  inputs=[question_input, source_code_input, llm_choice],
399
- outputs=[answer_output, retrieved_context_output]
400
  )
401
 
402
  # gradioUI.launch(server_name="localhost", server_port=7860)
 
132
  if page_text:
133
  text += page_text + "\n"
134
  # print(f" Page {i+1} extracted text (first 100 chars): {page_text[:100].replace('\n', ' ')}...")
135
+ cleaned_page_text = page_text[:100].replace('\n', ' ')
136
+ print(f" Page {i+1} extracted text (first 100 chars): {cleaned_page_text}...")
 
137
  else:
138
  print(f" Page {i+1} extracted no text.")
139
 
 
265
 
266
  # --- デバッグ用追加コード (前回のデバッグで追加したものは残しておくと良いでしょう) ---
267
  print(f"DEBUG: raw_text received from extract_text_from_pdf (length: {len(raw_text)})")
268
+ # print(f"DEBUG: raw_text starts with: '{raw_text[:100].replace(newline_char, ' ')}'")
269
  print(f"DEBUG: 'エラー' in raw_text: {'エラー' in raw_text}")
270
  print(f"DEBUG: '抽出できませんでした' in raw_text: {'抽出できませんでした' in raw_text}")
271
  print(f"DEBUG: 'PDFにページが含まれていません' in raw_text: {'PDFにページが含まれていません' in raw_text}")
 
349
  利用するLLMを選択してください。
350
  """
351
  )
 
352
  with gr.Row():
353
  with gr.Column():
354
  pdf_input = gr.File(label="PDFドキュメントをアップロード", file_types=[".pdf"], file_count="multiple")
 
394
  review_button.click(
395
  answer_question,
396
  inputs=[question_input, source_code_input, llm_choice],
397
+ outputs=[answer_output, retrieved_context_output]uv
398
  )
399
 
400
  # gradioUI.launch(server_name="localhost", server_port=7860)
checklist/test_sourcecode_001.txt ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <string.h>
4
+ #include <stdbool.h> // C99 standard for bool type
5
+
6
+ // 不必要に利用されるグローバルバッファ
7
+ char global_status_buffer[256];
8
+
9
+ // 関数プロトタイプ宣言
10
+ char* read_line_from_file(FILE* fp);
11
+ char* process_data(const char* input_str, int repeat_count);
12
+ void write_result_to_file(FILE* fp, const char* data);
13
+ void cleanup_memory(char* ptr); // メモリ解放を行うが、意図的に不完全な実装
14
+
15
+ int main(int argc, char *argv[]) {
16
+ FILE *input_file = NULL;
17
+ FILE *output_file = NULL;
18
+ char *read_data = NULL;
19
+ char *processed_data = NULL;
20
+ int default_repeat_count = 3; // マジックナンバー
21
+
22
+ // コマンドライン引数のチェックが不十分
23
+ if (argc != 3) {
24
+ printf("Usage: %s <input_file_path> <output_file_path>\n", argv[0]);
25
+ return 1; // エラー終了
26
+ }
27
+
28
+ // ファイルオープン時のエラーチェックが不十分
29
+ input_file = fopen(argv[1], "r");
30
+ if (input_file == NULL) {
31
+ perror("Error opening input file");
32
+ return 1; // エラー終了
33
+ }
34
+
35
+ output_file = fopen(argv[2], "w");
36
+ // output_fileのオープン失敗時のエラーハンドリングが欠落
37
+ // if (output_file == NULL) { ... }
38
+
39
+ // グローバルバッファに初期値を設定 (不必要かつバッファオーバーフローの可能性)
40
+ strcpy(global_status_buffer, "Program started successfully.");
41
+
42
+ // ファイルからデータを読み込む
43
+ read_data = read_line_from_file(input_file);
44
+ if (read_data == NULL) {
45
+ printf("No data read or an error occurred during read.\n");
46
+ // ここでinput_fileを閉じ忘れる
47
+ return 1; // エラー終了
48
+ }
49
+
50
+ printf("Read data: \"%s\"\n", read_data);
51
+
52
+ // データを処理する
53
+ processed_data = process_data(read_data, default_repeat_count);
54
+ if (processed_data == NULL) {
55
+ printf("Data processing failed.\n");
56
+ // ここでread_dataをfreeし忘れる
57
+ // ここでinput_file, output_fileを閉じ忘れる
58
+ return 1; // エラー終了
59
+ }
60
+
61
+ printf("Processed data: \"%s\"\n", processed_data);
62
+
63
+ // 結果をファイルに書き込む
64
+ write_result_to_file(output_file, processed_data);
65
+
66
+ // リソースのクリーンアップ (不完全な実装)
67
+ cleanup_memory(read_data); // read_dataはfreeされるが、processed_dataはされない
68
+ cleanup_memory(processed_data); // freeされたポインタを再度freeしようとする可能性 (未定義動作)
69
+
70
+ // ファイルを閉じる (output_fileがNULLの場合のチェックがないため、未定義動作の可能性)
71
+ fclose(input_file);
72
+ fclose(output_file);
73
+
74
+ // 初期化されていない変数の使用 (未定義動作)
75
+ bool is_finished;
76
+ if (is_finished) { // is_finishedは初期化されていないため、この条件は未定義動作
77
+ printf("Program finished with an unknown status.\n");
78
+ } else {
79
+ printf("Program finished.\n");
80
+ }
81
+
82
+ return 0; // 正常終了
83
+ }
84
+
85
+ // ファイルから1行読み込む関数
86
+ char* read_line_from_file(FILE* fp) {
87
+ char buffer[100]; // 固定長バッファ、バッファオーバーフローの可能性
88
+ if (fgets(buffer, sizeof(buffer), fp) == NULL) {
89
+ return NULL;
90
+ }
91
+
92
+ // 改行文字を削除
93
+ buffer[strcspn(buffer, "\n")] = 0;
94
+
95
+ char* result = (char*)malloc(strlen(buffer) + 1);
96
+ // mallocの戻り値チェックが欠落
97
+ // if (result == NULL) { ... }
98
+
99
+ strcpy(result, buffer); // bufferが100文字を超える場合のバッファオーバーフローの可能性
100
+ return result; // 呼び出し元でfreeされない (メモリリーク)
101
+ }
102
+
103
+ // データを処理する関数
104
+ char* process_data(const char* input_str, int repeat_count) {
105
+ int input_len = strlen(input_str);
106
+ // 適当なサイズ計算、mallocの戻り値チェックが欠落
107
+ char* temp_buffer = (char*)malloc(input_len * repeat_count + 20);
108
+ // if (temp_buffer == NULL) { ... }
109
+
110
+ // グローバルバッファを使用 (不必要かつバッファオーバーフローの可能性)
111
+ strcat(global_status_buffer, " Data processed.");
112
+
113
+ // 意図的に複雑で非効率なロジック
114
+ for (int i = 0; i < repeat_count; i++) {
115
+ if (i == 0) {
116
+ strcpy(temp_buffer, input_str); // バッファオーバーフローの可能性
117
+ } else {
118
+ strcat(temp_buffer, "-");
119
+ strcat(temp_buffer, input_str); // バッファオーバーフローの可能性
120
+ }
121
+ }
122
+
123
+ // 別の動的メモリを確保し、元のtemp_bufferをfreeするが、その後にtemp_bufferを使用する
124
+ char* final_result = (char*)malloc(strlen(temp_buffer) + 30); // 適当なサイズ
125
+ // if (final_result == NULL) { ... }
126
+
127
+ strcpy(final_result, "PROCESSED_");
128
+ strcat(final_result, temp_buffer); // temp_bufferはfreeされた後なので、use-after-free
129
+
130
+ free(temp_buffer); // ここでtemp_bufferをfree
131
+
132
+ // freeされたポインタを再度使用しようとしている (use-after-free)
133
+ printf("DEBUG: Intermediate buffer content (after free): %s\n", temp_buffer);
134
+
135
+ return final_result; // 呼び出し元でfreeされない (メモリリーク)
136
+ }
137
+
138
+ // 結果をファイルに書き込む関数
139
+ void write_result_to_file(FILE* fp, const char* data) {
140
+ // fpがNULLの場合のチェックが欠落
141
+ fprintf(fp, "Final Result: %s\n", data); // fprintfの戻り値チェックが欠落
142
+ }
143
+
144
+ // リソースクリーンアップ関数 (不完全なfree)
145
+ void cleanup_memory(char* ptr) {
146
+ if (ptr != NULL) {
147
+ free(ptr);
148
+ // ポインタをNULLにするが、これはローカル変数への代入であり、
149
+ // 呼び出し元のポインタには影響しないため、ダングリングポインタが残る
150
+ ptr = NULL;
151
+ }
152
+ }